@univerjs/docs 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +888 -768
- package/lib/types/commands/commands/delete.command.d.ts +1 -1
- package/lib/types/commands/commands/list.command.d.ts +3 -1
- package/lib/types/commands/commands/paragraph-align.command.d.ts +34 -0
- package/lib/types/doc-plugin.d.ts +2 -5
- package/lib/types/index.d.ts +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +10 -9
- package/lib/types/controllers/inline-format.controller.d.ts +0 -29
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { ICommand } from '@univerjs/core';
|
|
17
|
-
import type
|
|
17
|
+
import { type IActiveTextRange } from '@univerjs/engine-render';
|
|
18
18
|
import { DeleteDirection } from './core-editing.command';
|
|
19
19
|
export declare const DeleteLeftCommand: ICommand;
|
|
20
20
|
export declare const DeleteRightCommand: ICommand;
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { ICommand } from '@univerjs/core';
|
|
16
|
+
import type { ICommand, IParagraph } from '@univerjs/core';
|
|
17
17
|
import { PresetListType } from '@univerjs/core';
|
|
18
|
+
import type { IActiveTextRange } from '@univerjs/engine-render';
|
|
18
19
|
interface IListOperationCommandParams {
|
|
19
20
|
listType: PresetListType;
|
|
20
21
|
}
|
|
@@ -25,4 +26,5 @@ export declare const BulletListCommand: ICommand<IBulletListCommandParams>;
|
|
|
25
26
|
interface IOrderListCommandParams {
|
|
26
27
|
}
|
|
27
28
|
export declare const OrderListCommand: ICommand<IOrderListCommandParams>;
|
|
29
|
+
export declare function getParagraphsInRange(activeRange: IActiveTextRange, paragraphs: IParagraph[]): IParagraph[];
|
|
28
30
|
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { ICommand } from '@univerjs/core';
|
|
17
|
+
import { HorizontalAlign } from '@univerjs/core';
|
|
18
|
+
interface IAlignOperationCommandParams {
|
|
19
|
+
alignType: HorizontalAlign;
|
|
20
|
+
}
|
|
21
|
+
export declare const AlignOperationCommand: ICommand<IAlignOperationCommandParams>;
|
|
22
|
+
interface IAlignLeftCommandParams {
|
|
23
|
+
}
|
|
24
|
+
export declare const AlignLeftCommand: ICommand<IAlignLeftCommandParams>;
|
|
25
|
+
interface IAlignCenterCommandParams {
|
|
26
|
+
}
|
|
27
|
+
export declare const AlignCenterCommand: ICommand<IAlignCenterCommandParams>;
|
|
28
|
+
interface IAlignRightCommandParams {
|
|
29
|
+
}
|
|
30
|
+
export declare const AlignRightCommand: ICommand<IAlignRightCommandParams>;
|
|
31
|
+
interface IAlignJustifyCommandParams {
|
|
32
|
+
}
|
|
33
|
+
export declare const AlignJustifyCommand: ICommand<IAlignJustifyCommandParams>;
|
|
34
|
+
export {};
|
|
@@ -13,19 +13,16 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { Plugin, PluginType } from '@univerjs/core';
|
|
17
17
|
import { Injector } from '@wendellhu/redi';
|
|
18
18
|
export interface IUniverDocsConfig {
|
|
19
19
|
hasScroll?: boolean;
|
|
20
20
|
}
|
|
21
21
|
export declare class UniverDocsPlugin extends Plugin {
|
|
22
22
|
_injector: Injector;
|
|
23
|
-
private readonly _localeService;
|
|
24
|
-
private readonly _configService;
|
|
25
|
-
private readonly _currentUniverService;
|
|
26
23
|
static type: PluginType;
|
|
27
24
|
private _config;
|
|
28
|
-
constructor(config: Partial<IUniverDocsConfig> | undefined, _injector: Injector
|
|
25
|
+
constructor(config: Partial<IUniverDocsConfig> | undefined, _injector: Injector);
|
|
29
26
|
initialize(): void;
|
|
30
27
|
private _initializeCommands;
|
|
31
28
|
onReady(): void;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { DeleteCommand, type ICoverCommandParams, type IDeleteCommandParams, typ
|
|
|
21
21
|
export { DeleteLeftCommand, DeleteRightCommand } from './commands/commands/delete.command';
|
|
22
22
|
export { type IIMEInputCommandParams, IMEInputCommand } from './commands/commands/ime-input.command';
|
|
23
23
|
export { SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand, } from './commands/commands/inline-format.command';
|
|
24
|
+
export { AlignOperationCommand, AlignLeftCommand, AlignCenterCommand, AlignRightCommand, AlignJustifyCommand } from './commands/commands/paragraph-align.command';
|
|
24
25
|
export { BulletListCommand, OrderListCommand } from './commands/commands/list.command';
|
|
25
26
|
export { CoverContentCommand, ReplaceContentCommand } from './commands/commands/replace-content.command';
|
|
26
27
|
export { type IRichTextEditingMutationParams, RichTextEditingMutation, } from './commands/mutations/core-editing.mutation';
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@wendellhu/redi"],a):(d=typeof globalThis<"u"?globalThis:d||self,a(d.UniverDocs={},d.UniverCore,d.UniverEngineRender,d.rxjs,d["@wendellhu/redi"]))})(this,function(d,a,R,P,U){"use strict";var xt=Object.defineProperty;var Dt=(d,a,R)=>a in d?xt(d,a,{enumerable:!0,configurable:!0,writable:!0,value:R}):d[a]=R;var M=(d,a,R)=>(Dt(d,typeof a!="symbol"?a+"":a,R),R);var ve;function re(o,i){const t=o.getCurrentUniverDocInstance().getUnitId(),n=i.getRenderById(t);if(n==null)return;const{mainComponent:s,scene:r,engine:c}=n;return{document:s,scene:r,engine:c}}function Be(o,i){const e=i.getRenderById(o);if(e==null)return;const{mainComponent:t,scene:n,engine:s}=e;return{document:t,scene:n,engine:s}}var _e=(o=>(o.MAIN="__Document_Render_Main__",o))(_e||{}),Ie=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(Ie||{});const $e=0,Fe=2,Xe=10,Ve="normalTextSelectionPluginName",ce={id:"doc.operation.set-selections",type:a.CommandType.OPERATION,handler:(o,i)=>!0};var ke=Object.defineProperty,je=Object.getOwnPropertyDescriptor,ze=(o,i,e,t)=>{for(var n=t>1?void 0:t?je(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ke(i,e,n),n},Ce=(o,i)=>(e,t)=>i(e,t,o);function $(o){const{startOffset:i,endOffset:e,collapsed:t}=o,n={startOffset:i,endOffset:e,collapsed:t};return typeof o.isActive=="function"&&(n.isActive=o.isActive()),n}d.TextSelectionManagerService=class extends a.RxDisposable{constructor(e,t){super();M(this,"_currentSelection",null);M(this,"_textSelectionInfo",new Map);M(this,"_textSelection$",new P.BehaviorSubject(null));M(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:n,style:s}=e,r=t.find(f=>f.isActive());if(r==null)return null;const{startOffset:c,endOffset:l,collapsed:m,startNodePosition:u,endNodePosition:g,direction:S}=r;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:m,startNodePosition:u,endNodePosition:g,direction:S,segmentId:n,style:s}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:R.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:n,subUnitId:s,segmentId:r,style:c,textRanges:l,isEditing:m}=t;this._commandService.executeCommand(ce.id,{unitId:n,subUnitId:s,segmentId:r,style:c,isEditing:m,ranges:l.map($)})}_getTextRanges(e){var s;if(e==null)return;const{unitId:t,subUnitId:n=""}=e;return(s=this._textSelectionInfo.get(t))==null?void 0:s.get(n)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map($))}_replaceByParam(e){const{unitId:t,subUnitId:n,style:s,segmentId:r,textRanges:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{textRanges:c,style:s,segmentId:r,isEditing:l})}_addByParam(e){const{unitId:t,subUnitId:n,textRanges:s,style:r,segmentId:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const m=this._textSelectionInfo.get(t);m.has(n)?m.get(n).textRanges.push(...s):m.set(n,{textRanges:s,style:r,segmentId:c,isEditing:l})}},d.TextSelectionManagerService=ze([Ce(0,R.ITextSelectionRenderManager),Ce(1,a.ICommandService)],d.TextSelectionManagerService);function le(o,i="",e=0){const{startOffset:t,endOffset:n}=o,s=[],r=t-e,c=n-e;return r>0&&s.push({t:a.TextXActionType.RETAIN,len:r,segmentId:i}),s.push({t:a.TextXActionType.DELETE,len:c-r,line:0,segmentId:i}),s}var He=Object.defineProperty,Ge=Object.getOwnPropertyDescriptor,Ye=(o,i,e,t)=>{for(var n=t>1?void 0:t?Ge(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&He(i,e,n),n},We=(o,i)=>(e,t)=>i(e,t,o);d.DocViewModelManagerService=class extends a.RxDisposable{constructor(e){super();M(this,"_docViewModelMap",new Map);M(this,"_currentDocViewModel$",new P.BehaviorSubject(null));M(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._currentUniverService.currentDoc$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._currentUniverService.getAllUniverDocsInstance().forEach(e=>{this._create(e)}),this._currentUniverService.docDisposed$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._docViewModelMap.delete(e.getUnitId())})}_create(e){if(e==null)return;const t=e.getUnitId();this._setCurrent(t)}getAllModel(){return this._docViewModelMap}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var n;const t=this._currentUniverService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const s=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:s})}if(e===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const s=(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel;if(s==null)return;s.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new R.DocumentViewModel(e)}},d.DocViewModelManagerService=Ye([We(0,a.IUniverInstanceService)],d.DocViewModelManagerService);var Ze=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Ke=(o,i,e,t)=>{for(var n=t>1?void 0:t?qe(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&Ze(i,e,n),n},de=(o,i)=>(e,t)=>i(e,t,o);const Je=300;d.DocStateChangeManagerService=class extends a.RxDisposable{constructor(e,t,n){super();M(this,"_docStateChange$",new P.BehaviorSubject(null));M(this,"docStateChange$",this._docStateChange$.asObservable());M(this,"_stateCache",new Map);M(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=n,this._initialize()}setChangeState(e){const{trigger:t,noHistory:n}=e;t!=null&&(this._cacheChangeState(e),n||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===a.UndoCommandId||e.id===a.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const n=t.getUnitId();this._pushHistory(n)}}))}_cacheChangeState(e){const{trigger:t,unitId:n,noHistory:s}=e;if(!(t===a.RedoCommandId||t===a.UndoCommandId||s)){if(this._stateCache.has(n)){const r=this._stateCache.get(n);r==null||r.push(e)}else this._stateCache.set(n,[e]);t===X.id||t===V.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(n)},Je)):this._pushHistory(n)}}_pushHistory(e){const t=this._undoRedoService,n=this._stateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const s=n.length,r=n[0].commandId,c=n[0],l=n[s-1],m={unitId:e,actions:n.reduce((g,S)=>a.TextX.compose(g,S.redoState.actions),[]),textRanges:l.redoState.textRanges},u={unitId:e,actions:n.reverse().reduce((g,S)=>a.TextX.compose(g,S.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:u}],redoMutations:[{id:r,params:m}]}),n.length=0}},d.DocStateChangeManagerService=Ke([de(0,U.Inject(a.IUndoRedoService)),de(1,a.ICommandService),de(2,a.IUniverInstanceService)],d.DocStateChangeManagerService);class F{constructor(){M(this,"_previousActiveRange",null);M(this,"_undoMutationParamsCache",[]);M(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:i=[],redoCache:e=[]}){this._undoMutationParamsCache=i,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(i){this._previousActiveRange=i}pushUndoRedoMutationParams(i,e){this._undoMutationParamsCache.push(i),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:i}=this._undoMutationParamsCache[0],e={unitId:i,actions:this._undoMutationParamsCache.reverse().reduce((n,s)=>a.TextX.compose(n,s.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:i,actions:this._redoMutationParamsCache.reduce((n,s)=>a.TextX.compose(n,s.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Me="doc.mutation.rich-text-editing",N={id:Me,type:a.CommandType.MUTATION,handler:(o,i)=>{var x;const{unitId:e,actions:t,textRanges:n,prevTextRanges:s,trigger:r,noHistory:c,isCompositionEnd:l,noNeedSetTextRange:m}=i,g=o.get(a.IUniverInstanceService).getUniverDocInstance(e),f=o.get(d.DocViewModelManagerService).getViewModel(e),_=o.get(d.TextSelectionManagerService),h=((x=_.getSelections())!=null?x:[]).map($),I=o.get(d.DocStateChangeManagerService),v=o.get(F);if(g==null||f==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(t.length===0)return{unitId:e,actions:[],textRanges:h};const T=g.apply(t),{segmentId:y}=t[0],O=g.getSelfOrHeaderFooterModel(y);f.getSelfOrHeaderFooterViewModel(y).reset(O),!m&&n&&r!=null&&queueMicrotask(()=>{_.replaceTextRanges(n)});const E={commandId:Me,unitId:e,trigger:r,noHistory:c,redoState:{actions:t,textRanges:n},undoState:{actions:T,textRanges:s!=null?s:h}};if(l){const D=v.fetchComposedUndoRedoMutationParams();if(D==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:C,redoMutationParams:L,previousActiveRange:b}=D;E.redoState.actions=L.actions,E.undoState.actions=C.actions,E.undoState.textRanges=[b]}return I.setChangeState(E),{unitId:e,actions:T,textRanges:h}}},X={id:"doc.command.insert-text",type:a.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(a.ICommandService),{range:t,segmentId:n,body:s,unitId:r,textRanges:c}=i,{startOffset:l,collapsed:m}=t,u={id:N.id,params:{unitId:r,actions:[],textRanges:c}},g=new a.TextX;return m?l>0&&g.push({t:a.TextXActionType.RETAIN,len:l,segmentId:n}):g.push(...le(t,n)),g.push({t:a.TextXActionType.INSERT,body:s,len:s.dataStream.length,line:0,segmentId:n}),u.params.actions=g.serialize(),!!e.syncExecuteCommand(u.id,u.params)}};var w=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(w||{});const V={id:"doc.command.delete-text",type:a.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(a.ICommandService),{range:t,segmentId:n,unitId:s,direction:r,textRanges:c,len:l=1}=i,{startOffset:m}=t,u={id:N.id,params:{unitId:s,actions:[],textRanges:c}},g=new a.TextX;return m>0&&g.push({t:a.TextXActionType.RETAIN,len:r===0?m-l:m,segmentId:n}),g.push({t:a.TextXActionType.DELETE,len:l,line:0,segmentId:n}),u.params.actions=g.serialize(),!!e.syncExecuteCommand(u.id,u.params)}},ue={id:"doc.command.update-text",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{range:e,segmentId:t,updateBody:n,coverType:s,unitId:r,textRanges:c}=i,l=o.get(a.ICommandService),m={id:N.id,params:{unitId:r,actions:[],textRanges:c}},u=new a.TextX,{startOffset:g,endOffset:S}=e;return u.push({t:a.TextXActionType.RETAIN,len:g,segmentId:t}),u.push({t:a.TextXActionType.RETAIN,body:n,len:S-g,segmentId:t,coverType:s}),m.params.actions=u.serialize(),!!l.syncExecuteCommand(m.id,m.params)}};function Qe(o,i){const e=[];for(let t=0,n=o.length;t<n;t++)o[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(i)for(const t of e)i.bullet&&(t.bullet=a.Tools.deepClone(i.bullet)),i.paragraphStyle&&(t.paragraphStyle=a.Tools.deepClone(i.paragraphStyle));return e}const Te={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:async o=>{var _,p;const i=o.get(d.TextSelectionManagerService),e=o.get(a.IUniverInstanceService),t=o.get(a.ICommandService),n=i.getActiveRange();if(n==null)return!1;const s=e.getCurrentUniverDocInstance(),r=s.getUnitId(),{startOffset:c,segmentId:l,style:m}=n,u=[{startOffset:c+1,endOffset:c+1,style:m}],S=((p=(_=s.getBody())==null?void 0:_.paragraphs)!=null?p:[]).find(h=>h.startIndex>=c);return await t.executeCommand(X.id,{unitId:r,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Qe(a.DataStreamTreeTokenType.PARAGRAPH,S)},range:n,textRanges:u,segmentId:l})}};var et=Object.defineProperty,tt=Object.getOwnPropertyDescriptor,nt=(o,i,e,t)=>{for(var n=t>1?void 0:t?tt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&et(i,e,n),n},me=(o,i)=>(e,t)=>i(e,t,o);d.DocSkeletonManagerService=class extends a.RxDisposable{constructor(e,t,n){super();M(this,"_currentSkeletonUnitId","");M(this,"_docSkeletonMap",new Map);M(this,"_currentSkeleton$",new P.BehaviorSubject(null));M(this,"currentSkeleton$",this._currentSkeleton$.asObservable());M(this,"_currentSkeletonBefore$",new P.BehaviorSubject(null));M(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._currentUniverService=n,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._currentUniverService.docDisposed$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=this._currentUniverService.getCurrentUniverDocInstance().getUnitId()})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const n=this.getSkeletonByUnitId(e);n!=null&&(n.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const n=this.getSkeletonByUnitId(t);n.skeleton.calculate(),n.dirty=!0}else{const n=this._buildSkeleton(e.docViewModel);n.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:n,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return R.DocumentSkeleton.create(e,this._localeService)}},d.DocSkeletonManagerService=nt([me(0,U.Inject(a.LocaleService)),me(1,U.Inject(d.DocViewModelManagerService)),me(2,a.IUniverInstanceService)],d.DocSkeletonManagerService);const it={id:"doc.command.inner-paste",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,body:t,textRanges:n}=i,s=o.get(a.ICommandService),r=o.get(d.TextSelectionManagerService),c=o.get(a.IUniverInstanceService),l=r.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const u=c.getCurrentUniverDocInstance().getUnitId(),g={id:N.id,params:{unitId:u,actions:[],textRanges:n}},S=new a.MemoryCursor;S.reset();const f=new a.TextX;for(const p of l){const{startOffset:h,endOffset:I,collapsed:v}=p,T=h-S.cursor;v?f.push({t:a.TextXActionType.RETAIN,len:T,segmentId:e}):f.push(...le(p,e,S.cursor)),f.push({t:a.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!s.syncExecuteCommand(g.id,g.params)}},ge={id:"doc.command.inner-cut",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,textRanges:t}=i,n=o.get(a.ICommandService),s=o.get(d.TextSelectionManagerService),r=o.get(a.IUniverInstanceService),c=s.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=r.getCurrentUniverDocInstance().getUnitId(),m=r.getUniverDocInstance(l),u=a.getDocsUpdateBody(m.snapshot,e);if(u==null)return!1;const g={id:N.id,params:{unitId:l,actions:[],textRanges:t}},S=new a.MemoryCursor;S.reset();const f=new a.TextX;for(const p of c){const{startOffset:h,endOffset:I,collapsed:v}=p,T=h-S.cursor;v?f.push({t:a.TextXActionType.RETAIN,len:T,segmentId:e}):f.push(...at(p,u,e,S.cursor)),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!n.syncExecuteCommand(g.id,g.params)}};function at(o,i,e="",t=0){const{startOffset:n,endOffset:s}=o,r=[],{paragraphs:c=[]}=i,l=n-t,m=s-t,u=c==null?void 0:c.find(g=>g.startIndex-t>=l&&g.startIndex-t<=m);if(l>0&&r.push({t:a.TextXActionType.RETAIN,len:l,segmentId:e}),u&&u.startIndex-t>l){const g=u.startIndex-t;r.push({t:a.TextXActionType.DELETE,len:g-l,line:0,segmentId:e}),r.push({t:a.TextXActionType.RETAIN,len:1,segmentId:e}),m>g+1&&r.push({t:a.TextXActionType.DELETE,len:m-g-1,line:0,segmentId:e})}else r.push({t:a.TextXActionType.DELETE,len:m-l,line:0,segmentId:e});return r}const ye={id:"doc.command.delete-left",type:a.CommandType.COMMAND,handler:async o=>{var y;const i=o.get(d.TextSelectionManagerService),e=o.get(d.DocSkeletonManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),s=i.getActiveRange(),r=i.getSelections(),c=(y=e.getCurrent())==null?void 0:y.skeleton;let l=!0;if(s==null||c==null||r==null)return!1;const m=t.getCurrentUniverDocInstance(),{startOffset:u,collapsed:g,segmentId:S,style:f}=s,_=c.findNodeByCharIndex(u),p=R.hasListSpan(_),h=R.isIndentBySpan(_,m.getBody());let I=u;const v=c.findNodeByCharIndex(u-1);if(R.isFirstSpan(_)&&v!==_&&(p===!0||h===!0)){const O=R.getParagraphBySpan(_,m.getBody());if(O==null)return!1;const A=O==null?void 0:O.startIndex,E={startIndex:0},x=O.paragraphStyle;if(p===!0){const C=O.paragraphStyle;C&&(E.paragraphStyle=C)}else if(h===!0){const C=O.bullet;C&&(E.bullet=C),x!=null&&(E.paragraphStyle={...x},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const D=[{startOffset:I,endOffset:I,style:f}];l=await n.executeCommand(ue.id,{unitId:m.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:A,endOffset:A+1},textRanges:D,coverType:a.UpdateDocsAttributeType.REPLACE,segmentId:S})}else if(g===!0){if(v==null)return!0;if(v.content==="\r")l=await n.executeCommand(Se.id,{direction:w.LEFT,range:s});else{I-=v.count;const O=[{startOffset:I,endOffset:I,style:f}];l=await n.executeCommand(V.id,{unitId:m.getUnitId(),range:s,segmentId:S,direction:w.LEFT,len:v.count,textRanges:O})}}else{const O=Re(s,r);l=await n.executeCommand(ge.id,{segmentId:S,textRanges:O})}return l}},Oe={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async o=>{var _;const i=o.get(d.TextSelectionManagerService),e=o.get(d.DocSkeletonManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),s=i.getActiveRange(),r=i.getSelections(),c=(_=e.getCurrent())==null?void 0:_.skeleton;let l;if(s==null||c==null||r==null)return!1;const m=t.getCurrentUniverDocInstance(),{startOffset:u,collapsed:g,segmentId:S,style:f}=s;if(u===m.getBody().dataStream.length-2&&g)return!0;if(g===!0){const p=c.findNodeByCharIndex(u);if(p.content==="\r")l=await n.executeCommand(Se.id,{direction:w.RIGHT,range:s});else{const h=[{startOffset:u,endOffset:u,style:f}];l=await n.executeCommand(V.id,{unitId:m.getUnitId(),range:s,segmentId:S,direction:w.RIGHT,textRanges:h,len:p.count})}}else{const p=Re(s,r);l=await n.executeCommand(ge.id,{segmentId:S,textRanges:p})}return l}},Se={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(o,i)=>{var E,x,D;const e=o.get(d.TextSelectionManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService);o.get(a.IUndoRedoService);const{direction:s,range:r}=i,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const m=t.getCurrentUniverDocInstance(),{startOffset:u,collapsed:g,segmentId:S,style:f}=c;if(!g)return!1;const _=s===w.LEFT?u:u+1,p=(D=(x=(E=m.getBody())==null?void 0:E.paragraphs)==null?void 0:x.find(C=>C.startIndex>=_))==null?void 0:D.startIndex,h=st(m.getBody(),_,p),I=s===w.LEFT?u-1:u,v=m.getUnitId(),T=[{startOffset:I,endOffset:I,style:f}],y={id:N.id,params:{unitId:v,actions:[],textRanges:T,prevTextRanges:[r]}},O=new a.TextX;return O.push({t:a.TextXActionType.RETAIN,len:s===w.LEFT?u-1:u,segmentId:S}),h.dataStream.length&&O.push({t:a.TextXActionType.INSERT,body:h,len:h.dataStream.length,line:0,segmentId:S}),O.push({t:a.TextXActionType.RETAIN,len:1,segmentId:S}),O.push({t:a.TextXActionType.DELETE,len:p+1-_,line:0,segmentId:S}),y.params.actions=O.serialize(),!!n.syncExecuteCommand(y.id,y.params)}};function st(o,i,e){const{textRuns:t}=o,n=o.dataStream.substring(i,e);if(t==null)return{dataStream:n};const s=[];for(const r of t){const{st:c,ed:l}=r;l<=i||c>=e||(c<i?s.push({...r,st:0,ed:l-i}):l>e?s.push({...r,st:c-i,ed:e-i}):s.push({...r,st:c-i,ed:l-i}))}return{dataStream:n,textRuns:s}}function Re(o,i){let e=o.endOffset;for(const n of i){const{startOffset:s,endOffset:r}=n;s==null||r==null||r<=o.endOffset&&(e-=r-s)}return[{startOffset:e,endOffset:e,style:o.style}]}const fe={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{unitId:e,newText:t,oldTextLen:n,isCompositionEnd:s,isCompositionStart:r}=i,c=o.get(a.ICommandService),l=o.get(F),m=l.getActiveRange();if(m==null)return!1;const{startOffset:u,style:g,segmentId:S}=m,f=t.length,_=[{startOffset:u+f,endOffset:u+f,collapsed:!0,style:g}],p={id:N.id,params:{unitId:e,actions:[],textRanges:_}},h=new a.TextX;!m.collapsed&&r?h.push(...le(m,S)):h.push({t:a.TextXActionType.RETAIN,len:u,segmentId:S}),n>0&&h.push({t:a.TextXActionType.DELETE,len:n,line:0,segmentId:S}),h.push({t:a.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:S}),p.params.actions=h.serialize(),p.params.noHistory=!s,p.params.isCompositionEnd=s;const I=c.syncExecuteCommand(p.id,p.params);return l.pushUndoRedoMutationParams(I,p.params),!!I}},k={id:"doc.command.set-inline-format-bold",type:a.CommandType.COMMAND,handler:async()=>!0},j={id:"doc.command.set-inline-format-italic",type:a.CommandType.COMMAND,handler:async()=>!0},z={id:"doc.command.set-inline-format-underline",type:a.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-strikethrough",type:a.CommandType.COMMAND,handler:async()=>!0},B={id:"doc.command.set-inline-format-subscript",type:a.CommandType.COMMAND,handler:async()=>!0},G={id:"doc.command.set-inline-format-superscript",type:a.CommandType.COMMAND,handler:async()=>!0},Y={id:"doc.command.set-inline-format-fontsize",type:a.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-font-family",type:a.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-text-color",type:a.CommandType.COMMAND,handler:async()=>!0},xe={[k.id]:"bl",[j.id]:"it",[z.id]:"ul",[H.id]:"st",[Y.id]:"fs",[W.id]:"ff",[Z.id]:"cl",[B.id]:"va",[G.id]:"va"},he={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,value:t,preCommandId:n}=i,s=o.get(a.ICommandService),r=o.get(d.TextSelectionManagerService),c=o.get(a.IUniverInstanceService),l=r.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let m=c.getCurrentUniverDocInstance(),u=m.getUnitId();u===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(m=c.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),u=m.getUnitId());let g;switch(n){case k.id:case j.id:case z.id:case H.id:case B.id:case G.id:{g=rt(m.getBody().textRuns,n,l);break}case Y.id:case W.id:{g=t;break}case Z.id:{g={rgb:t};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const S={id:N.id,params:{unitId:u,actions:[],textRanges:l.map($)}},f=new a.TextX,_=new a.MemoryCursor;_.reset();for(const h of l){const{startOffset:I,endOffset:v}=h,T={dataStream:"",textRuns:[{st:0,ed:v-I,ts:{[xe[n]]:g}}]},y=I-_.cursor;y!==0&&f.push({t:a.TextXActionType.RETAIN,len:y,segmentId:e}),f.push({t:a.TextXActionType.RETAIN,body:T,len:v-I,segmentId:e}),_.reset(),_.moveCursor(v)}return S.params.actions=f.serialize(),!!s.syncExecuteCommand(S.id,S.params)}};function ot(o){return o!==null&&typeof o=="object"}function rt(o,i,e){let t=0,n=0;const s=xe[i];for(;t!==o.length&&n!==e.length;){const{startOffset:r,endOffset:c}=e[n],{st:l,ed:m,ts:u}=o[t];if(c<=l)n++;else if(m<=r)t++;else{if(/bl|it/.test(s))return(u==null?void 0:u[s])===a.BooleanNumber.TRUE?a.BooleanNumber.FALSE:a.BooleanNumber.TRUE;if(/ul|st/.test(s))return ot(u==null?void 0:u[s])&&(u==null?void 0:u[s]).s===a.BooleanNumber.TRUE?{s:a.BooleanNumber.FALSE}:{s:a.BooleanNumber.TRUE};if(/va/.test(s))return i===B.id?(u==null?void 0:u[s])===a.BaselineOffset.SUBSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUBSCRIPT:(u==null?void 0:u[s])===a.BaselineOffset.SUPERSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(s)?a.BooleanNumber.TRUE:/ul|st/.test(s)?{s:a.BooleanNumber.TRUE}:i===B.id?a.BaselineOffset.SUBSCRIPT:a.BaselineOffset.SUPERSCRIPT}const pe={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(o,i)=>{var O,A,E;const e=o.get(d.TextSelectionManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),{listType:s}=i,r=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),l=(O=e.getSelections())!=null?O:[],m=(A=r.getBody())==null?void 0:A.paragraphs,u=l.map($);if(c==null||m==null)return!1;const g=ct(c,m),{segmentId:S}=c,f=r.getUnitId(),_=g.every(x=>{var D;return((D=x.bullet)==null?void 0:D.listType)===s});let h=a.Tools.generateRandomId(6);if(g.length===1){const x=m.indexOf(g[0]),D=m[x-1],C=m[x+1];D&&D.bullet&&D.bullet.listType===s?h=D.bullet.listId:C&&C.bullet&&C.bullet.listType===s&&(h=C.bullet.listId)}const I={id:N.id,params:{unitId:f,actions:[],textRanges:u}},v=new a.MemoryCursor;v.reset();const T=new a.TextX;for(const x of g){const{startIndex:D}=x;T.push({t:a.TextXActionType.RETAIN,len:D-v.cursor,segmentId:S});const C={...x.paragraphStyle,hanging:void 0,indentStart:void 0};T.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[_?{paragraphStyle:C,startIndex:0}:{...x,startIndex:0,bullet:{...(E=x.bullet)!=null?E:{nestingLevel:0,textStyle:{fs:20}},listType:s,listId:h}}]},segmentId:S,coverType:a.UpdateDocsAttributeType.REPLACE}),v.moveCursorTo(D+1)}return I.params.actions=T.serialize(),!!n.syncExecuteCommand(I.id,I.params)}},De={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(pe.id,{listType:a.PresetListType.BULLET_LIST})},Ee={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(pe.id,{listType:a.PresetListType.ORDER_LIST})};function ct(o,i){const{startOffset:e,endOffset:t}=o,n=[];let s=-1;for(const r of i){const{startIndex:c}=r;(e>s&&e<=c||t>s&&t<=c||c>=e&&c<=t)&&n.push(r),s=c}return n}const Ae={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(o,i)=>{var f;const{unitId:e,body:t,textRanges:n,segmentId:s=""}=i,r=o.get(a.IUniverInstanceService),c=o.get(a.ICommandService),l=o.get(d.TextSelectionManagerService),m=(f=r.getUniverDocInstance(e))==null?void 0:f.getSnapshot().body,u=l.getSelections();if(m==null||!Array.isArray(u)||u.length===0)return!1;const g=Ne(e,s,m,t);return g.params.textRanges=n,!!c.syncExecuteCommand(g.id,g.params)}},Ue={id:"doc.command-cover-content",type:a.CommandType.COMMAND,handler:async(o,i)=>{var u;const{unitId:e,body:t,segmentId:n=""}=i,s=o.get(a.IUniverInstanceService),r=o.get(a.ICommandService),c=o.get(a.IUndoRedoService),l=(u=s.getUniverDocInstance(e))==null?void 0:u.getSnapshot().body;if(l==null)return!1;const m=Ne(e,n,l,t);return m.params.noNeedSetTextRange=!0,m.params.noHistory=!0,r.syncExecuteCommand(m.id,m.params),c.clearUndoRedo(e),!0}};function Ne(o,i,e,t){const n={id:N.id,params:{unitId:o,actions:[],textRanges:[]}},s=new a.TextX,r=(e==null?void 0:e.dataStream.length)-2;return r>0&&s.push({t:a.TextXActionType.DELETE,len:r,line:0,segmentId:i}),t.dataStream.length>0&&s.push({t:a.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:i}),n.params.actions=s.serialize(),n}const ee={id:"doc.operation.move-cursor",type:a.CommandType.OPERATION,handler:(o,i)=>!!i},te={id:"doc.operation.move-selection",type:a.CommandType.OPERATION,handler:(o,i)=>!!i},lt=(o,i)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(i.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...a.Tools.deepClone(i),zoomRatio:t}},q={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(o,i)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(i.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:i.zoomRatio}:t.settings.zoomRatio=i.zoomRatio,!0}},Pe={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,i)=>{var g,S;const e=o.get(a.ICommandService),t=o.get(a.IUndoRedoService),n=o.get(a.IUniverInstanceService);let s=n.getCurrentUniverDocInstance().getUnitId(),r=1;if(i&&(s=(g=i.documentId)!=null?g:s,r=(S=i.zoomRatio)!=null?S:r),!n.getUniverDocInstance(s))return!1;const l={zoomRatio:r,unitId:s},m=lt(o,l);return e.syncExecuteCommand(q.id,l)?(t.pushUndoRedo({unitID:s,undoMutations:[{id:q.id,params:m}],redoMutations:[{id:q.id,params:l}]}),!0):!1}},be={id:"doc.operation.select-all",type:a.CommandType.COMMAND,handler:async o=>{const i=o.get(a.IUniverInstanceService),e=o.get(d.TextSelectionManagerService),t=i.getCurrentUniverDocInstance().getSnapshot().body;if(t==null)return!1;const n=[{startOffset:0,endOffset:t.dataStream.length-2}];return e.replaceTextRanges(n,!1),!0}};var dt=Object.defineProperty,ut=Object.getOwnPropertyDescriptor,mt=(o,i,e,t)=>{for(var n=t>1?void 0:t?ut(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&dt(i,e,n),n},K=(o,i)=>(e,t)=>i(e,t,o);let ne=class extends a.Disposable{constructor(i,e,t,n,s){super();M(this,"_previousIMEContent","");M(this,"_isCompositionStart",!0);M(this,"_onStartSubscription");M(this,"_onUpdateSubscription");M(this,"_onEndSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=n,this._commandService=s,this._initialize()}dispose(){var i,e,t;(i=this._onStartSubscription)==null||i.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(t=this._onEndSubscription)==null||t.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(i=>{if(i==null)return;this._resetIME();const{activeRange:e}=i;e!=null&&this._imeInputManagerService.setActiveRange(a.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async i=>{this._updateContent(i,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(i=>{this._updateContent(i,!1)})}async _updateContent(i,e){var m;const t=(m=this._docSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(i==null||t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance(),{event:s,activeRange:r}=i;if(t==null||r==null)return;const l=s.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(fe.id,{unitId:n.getUnitId(),newText:l,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=l):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};ne=mt([a.OnLifecycle(a.LifecycleStages.Rendered,ne),K(0,U.Inject(d.DocSkeletonManagerService)),K(1,a.IUniverInstanceService),K(2,R.ITextSelectionRenderManager),K(3,U.Inject(F)),K(4,a.ICommandService)],ne);var gt=Object.defineProperty,St=Object.getOwnPropertyDescriptor,ft=(o,i,e,t)=>{for(var n=t>1?void 0:t?St(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&>(i,e,n),n},we=(o,i)=>(e,t)=>i(e,t,o);let ie=class extends a.Disposable{constructor(o,i){super(),this._textSelectionManagerService=o,this._commandService=i,this._commandExecutedListener()}_commandExecutedListener(){const o=[k.id,j.id,z.id,H.id,B.id,G.id,Y.id,W.id,Z.id];this.disposeWithMe(this._commandService.onCommandExecuted(i=>{o.includes(i.id)&&this._handleInlineFormat(i)}))}_handleInlineFormat(o){var e,t;const{segmentId:i}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};i!=null&&this._commandService.executeCommand(he.id,{segmentId:i,preCommandId:o.id,...(t=o.params)!=null?t:{}})}};ie=ft([a.OnLifecycle(a.LifecycleStages.Rendered,ie),we(0,U.Inject(d.TextSelectionManagerService)),we(1,a.ICommandService)],ie);var ht=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,vt=(o,i,e,t)=>{for(var n=t>1?void 0:t?pt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ht(i,e,n),n},J=(o,i)=>(e,t)=>i(e,t,o);let ae=class extends a.Disposable{constructor(i,e,t,n,s){super();M(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionManagerService=n,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){}_commandExecutedListener(){const i=[ee.id,te.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!i.includes(e.id))return;const t=e.params;switch(e.id){case ee.id:return this._handleMoveCursor(t.direction);case te.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(i){var p,h,I;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),s=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton,r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:c,endOffset:l,style:m,collapsed:u,direction:g}=e;if(t.length>1){let v=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const y of t)v=Math.min(v,y.startOffset),T=Math.max(T,y.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:i===a.Direction.LEFT||i===a.Direction.UP?T:v,endOffset:i===a.Direction.LEFT||i===a.Direction.UP?v:T,style:m}],!1);return}const S=u||g===R.RANGE_DIRECTION.FORWARD?c:l;let f=u||g===R.RANGE_DIRECTION.FORWARD?l:c;const _=(h=n.getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(i===a.Direction.LEFT||i===a.Direction.RIGHT){const v=s.findNodeByCharIndex(f-1),T=s.findNodeByCharIndex(f);f=i===a.Direction.RIGHT?f+T.count:f-((I=v==null?void 0:v.count)!=null?I:0),f=Math.min(_-2,Math.max(0,f)),this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:f,style:m}],!1)}else{const v=s.findNodeByCharIndex(f),T=r.document.getOffsetConfig(),y=this._getTopOrBottomPosition(s,v,i===a.Direction.DOWN);if(y==null){const A=i===a.Direction.UP?0:_-2;if(A===f)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:A,style:m}],!1);return}const O=new R.NodePositionConvertToCursor(T,s).getRangePointData(y,y).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:O.endOffset,style:m}],!1)}}_handleMoveCursor(i){var S,f,_;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,r=this._getDocObject();if(e==null||s==null||r==null||t==null)return;const{startOffset:c,endOffset:l,style:m,collapsed:u}=e,g=(f=n.getBody().dataStream.length)!=null?f:Number.POSITIVE_INFINITY;if(i===a.Direction.LEFT||i===a.Direction.RIGHT){let p;if(!e.collapsed||t.length>1){let h=Number.POSITIVE_INFINITY,I=Number.NEGATIVE_INFINITY;for(const v of t)h=Math.min(h,v.startOffset),I=Math.max(I,v.endOffset);p=i===a.Direction.LEFT?h:I}else{const h=s.findNodeByCharIndex(c-1),I=s.findNodeByCharIndex(c);i===a.Direction.LEFT?p=Math.max(0,c-((_=h==null?void 0:h.count)!=null?_:0)):p=Math.min(g-2,l+I.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:p,style:m}],!1)}else{const p=s.findNodeByCharIndex(c),h=s.findNodeByCharIndex(l),I=r.document.getOffsetConfig(),v=this._getTopOrBottomPosition(s,i===a.Direction.UP?p:h,i===a.Direction.DOWN);if(v==null){let y;u?y=i===a.Direction.UP?0:g-2:y=i===a.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:y,endOffset:y,style:m}],!1);return}const T=new R.NodePositionConvertToCursor(I,s).getRangePointData(v,v).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...T,style:m}],!1)}}_getTopOrBottomPosition(i,e,t){if(e==null)return;const n=this._getSpanLeftOffsetInLine(e),s=this._getNextOrPrevLine(e,t);if(s==null)return;const r=this._matchPositionByLeftOffset(i,s,n);if(r!=null)return{...r,isBack:!0}}_getSpanLeftOffsetInLine(i){const e=i.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:n}=i;return t+n}_matchPositionByLeftOffset(i,e,t){const n={distance:Number.POSITIVE_INFINITY};for(const s of e.divides){const r=s.left;for(const c of s.spanGroup){const{left:l}=c,m=r+l,u=Math.abs(t-m);u<n.distance&&(n.span=c,n.distance=u)}}if(n.span!=null)return i.findPositionBySpan(n.span)}_getNextOrPrevLine(i,e){var _,p,h,I,v,T,y,O,A,E,x,D;const t=i.parent;if(t==null)return;const n=t.parent;if(n==null)return;const s=n.parent;if(s==null)return;const r=s.lines.indexOf(n);if(r===-1)return;let c;if(e===!0?c=s.lines[r+1]:c=s.lines[r-1],c!=null)return c;const l=s.parent;if(l==null)return;const m=l.columns.indexOf(s);if(m===-1)return;if(e===!0)c=(_=l.columns[m+1])==null?void 0:_.lines[0];else{const C=(h=(p=l.columns)==null?void 0:p[m-1])==null?void 0:h.lines;c=C==null?void 0:C[C.length-1]}if(c!=null)return c;const u=l.parent;if(u==null)return;const g=u.sections.indexOf(l);if(g===-1)return;if(e===!0)c=(v=(I=u.sections[g-1])==null?void 0:I.columns[0])==null?void 0:v.lines[0];else{const C=(y=(T=u.sections)==null?void 0:T[g-1])==null?void 0:y.columns,L=C==null?void 0:C[C.length-1],b=L==null?void 0:L.lines;c=b==null?void 0:b[b.length-1]}if(c!=null)return c;const S=u.parent;if(S==null)return;const f=S.pages.indexOf(u);if(f!==-1){if(e===!0)c=(E=(A=(O=S.pages[f+1])==null?void 0:O.sections[0])==null?void 0:A.columns[0])==null?void 0:E.lines[0];else{const C=(x=S.pages[f-1])==null?void 0:x.sections;if(C==null)return;const L=(D=C[C.length-1])==null?void 0:D.columns,b=L[L.length-1],Le=b==null?void 0:b.lines;c=Le[Le.length-1]}if(c!=null)return c}}_getDocObject(){return re(this._currentUniverService,this._renderManagerService)}};ae=vt([a.OnLifecycle(a.LifecycleStages.Rendered,ae),J(0,U.Inject(d.DocSkeletonManagerService)),J(1,a.IUniverInstanceService),J(2,R.IRenderManagerService),J(3,U.Inject(d.TextSelectionManagerService)),J(4,a.ICommandService)],ae);var _t=Object.defineProperty,It=Object.getOwnPropertyDescriptor,Ct=(o,i,e,t)=>{for(var n=t>1?void 0:t?It(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&_t(i,e,n),n},Q=(o,i)=>(e,t)=>i(e,t,o);let se=class extends a.Disposable{constructor(i,e,t,n,s){super();M(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionRenderManager=n,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async i=>{var _;if(i==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:n,content:s="",activeRange:r}=i,c=n,l=(_=this._docSkeletonManagerService.getCurrent())==null?void 0:_.skeleton;if(c.data==null||l==null||!l||!r)return;const{startOffset:m,segmentId:u,style:g}=r,S=s.length,f=[{startOffset:m+S,endOffset:m+S,style:g}];await this._commandService.executeCommand(X.id,{unitId:t,body:{dataStream:s},range:r,textRanges:f,segmentId:u})})}_commandExecutedListener(){}_getDocObject(){return re(this._currentUniverService,this._renderManagerService)}};se=Ct([a.OnLifecycle(a.LifecycleStages.Rendered,se),Q(0,U.Inject(d.DocSkeletonManagerService)),Q(1,a.IUniverInstanceService),Q(2,R.IRenderManagerService),Q(3,R.ITextSelectionRenderManager),Q(4,a.ICommandService)],se);var Mt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,yt=(o,i,e,t)=>{for(var n=t>1?void 0:t?Tt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&Mt(i,e,n),n},oe=(o,i)=>(e,t)=>i(e,t,o);const Ot={hasScroll:!0},Rt="docs";d.UniverDocsPlugin=(ve=class extends a.Plugin{constructor(e={},t,n,s,r){super(Rt);M(this,"_config");this._injector=t,this._localeService=n,this._configService=s,this._currentUniverService=r,this._config=Object.assign(Ot,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[ee,te,ye,Oe,k,j,z,H,B,G,Y,W,Z,he,Te,X,V,ue,fe,Se,N,Ae,Ue,Pe,q,ce,be,Ee,De,pe].forEach(e=>{this._injector.get(a.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[d.DocSkeletonManagerService],[d.DocViewModelManagerService],[d.DocStateChangeManagerService],[F],[R.ITextSelectionRenderManager,{useClass:R.TextSelectionRenderManager}],[d.TextSelectionManagerService],[se],[ne],[ie],[ae]].forEach(t=>e.add(t))}},M(ve,"type",a.PluginType.Doc),ve),d.UniverDocsPlugin=yt([oe(1,U.Inject(U.Injector)),oe(2,U.Inject(a.LocaleService)),oe(3,a.IConfigService),oe(4,a.IUniverInstanceService)],d.UniverDocsPlugin),d.BreakLineCommand=Te,d.BulletListCommand=De,d.CoverContentCommand=Ue,d.CutContentCommand=ge,d.DOCS_COMPONENT_DEFAULT_Z_INDEX=Xe,d.DOCS_COMPONENT_HEADER_LAYER_INDEX=Fe,d.DOCS_COMPONENT_MAIN_LAYER_INDEX=$e,d.DOCS_VIEW_KEY=_e,d.DeleteCommand=V,d.DeleteLeftCommand=ye,d.DeleteRightCommand=Oe,d.IMEInputCommand=fe,d.IMEInputManagerService=F,d.InnerPasteCommand=it,d.InsertCommand=X,d.MoveCursorOperation=ee,d.MoveSelectionOperation=te,d.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Ve,d.OrderListCommand=Ee,d.ReplaceContentCommand=Ae,d.RichTextEditingMutation=N,d.SelectAllOperation=be,d.SetDocZoomRatioCommand=Pe,d.SetDocZoomRatioOperation=q,d.SetInlineFormatBoldCommand=k,d.SetInlineFormatCommand=he,d.SetInlineFormatFontFamilyCommand=W,d.SetInlineFormatFontSizeCommand=Y,d.SetInlineFormatItalicCommand=j,d.SetInlineFormatStrikethroughCommand=H,d.SetInlineFormatSubscriptCommand=B,d.SetInlineFormatSuperscriptCommand=G,d.SetInlineFormatTextColorCommand=Z,d.SetInlineFormatUnderlineCommand=z,d.SetTextSelectionsOperation=ce,d.UpdateCommand=ue,d.VIEWPORT_KEY=Ie,d.getDocObject=re,d.getDocObjectById=Be,d.serializeTextRange=$,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(l,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@wendellhu/redi"],i):(l=typeof globalThis<"u"?globalThis:l||self,i(l.UniverDocs={},l.UniverCore,l.UniverEngineRender,l.rxjs,l["@wendellhu/redi"]))})(this,function(l,i,O,N,b){"use strict";var Bt=Object.defineProperty;var Ft=(l,i,O)=>i in l?Bt(l,i,{enumerable:!0,configurable:!0,writable:!0,value:O}):l[i]=O;var R=(l,i,O)=>(Ft(l,typeof i!="symbol"?i+"":i,O),O);var Ie;function ce(o,n){const t=o.getCurrentUniverDocInstance().getUnitId(),a=n.getRenderById(t);if(a==null)return;const{mainComponent:s,scene:r,engine:c}=a;return{document:s,scene:r,engine:c}}function qe(o,n){const e=n.getRenderById(o);if(e==null)return;const{mainComponent:t,scene:a,engine:s}=e;return{document:t,scene:a,engine:s}}var _e=(o=>(o.MAIN="__Document_Render_Main__",o))(_e||{}),Ce=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(Ce||{});const Je=0,Ke=2,Qe=10,et="normalTextSelectionPluginName",le={id:"doc.operation.set-selections",type:i.CommandType.OPERATION,handler:(o,n)=>!0};var tt=Object.defineProperty,nt=Object.getOwnPropertyDescriptor,it=(o,n,e,t)=>{for(var a=t>1?void 0:t?nt(n,e):n,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(n,e,a):r(a))||a);return t&&a&&tt(n,e,a),a},Me=(o,n)=>(e,t)=>n(e,t,o);function F(o){const{startOffset:n,endOffset:e,collapsed:t}=o,a={startOffset:n,endOffset:e,collapsed:t};return typeof o.isActive=="function"&&(a.isActive=o.isActive()),a}l.TextSelectionManagerService=class extends i.RxDisposable{constructor(e,t){super();R(this,"_currentSelection",null);R(this,"_textSelectionInfo",new Map);R(this,"_textSelection$",new N.BehaviorSubject(null));R(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:a,style:s}=e,r=t.find(f=>f.isActive());if(r==null)return null;const{startOffset:c,endOffset:d,collapsed:u,startNodePosition:m,endNodePosition:g,direction:S}=r;return c==null||d==null?null:{startOffset:c,endOffset:d,collapsed:u,startNodePosition:m,endNodePosition:g,direction:S,segmentId:a,style:s}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:O.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:a,subUnitId:s,segmentId:r,style:c,textRanges:d,isEditing:u}=t;this._commandService.executeCommand(le.id,{unitId:a,subUnitId:s,segmentId:r,style:c,isEditing:u,ranges:d.map(F)})}_getTextRanges(e){var s;if(e==null)return;const{unitId:t,subUnitId:a=""}=e;return(s=this._textSelectionInfo.get(t))==null?void 0:s.get(a)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(F))}_replaceByParam(e){const{unitId:t,subUnitId:a,style:s,segmentId:r,textRanges:c,isEditing:d}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(a,{textRanges:c,style:s,segmentId:r,isEditing:d})}_addByParam(e){const{unitId:t,subUnitId:a,textRanges:s,style:r,segmentId:c,isEditing:d}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const u=this._textSelectionInfo.get(t);u.has(a)?u.get(a).textRanges.push(...s):u.set(a,{textRanges:s,style:r,segmentId:c,isEditing:d})}},l.TextSelectionManagerService=it([Me(0,O.ITextSelectionRenderManager),Me(1,i.ICommandService)],l.TextSelectionManagerService);function de(o,n="",e=0){const{startOffset:t,endOffset:a}=o,s=[],r=t-e,c=a-e;return r>0&&s.push({t:i.TextXActionType.RETAIN,len:r,segmentId:n}),s.push({t:i.TextXActionType.DELETE,len:c-r,line:0,segmentId:n}),s}var at=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,st=(o,n,e,t)=>{for(var a=t>1?void 0:t?ot(n,e):n,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(n,e,a):r(a))||a);return t&&a&&at(n,e,a),a},rt=(o,n)=>(e,t)=>n(e,t,o);l.DocViewModelManagerService=class extends i.RxDisposable{constructor(e){super();R(this,"_docViewModelMap",new Map);R(this,"_currentDocViewModel$",new N.BehaviorSubject(null));R(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._currentUniverService.currentDoc$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._currentUniverService.getAllUniverDocsInstance().forEach(e=>{this._create(e)}),this._currentUniverService.docDisposed$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{this._docViewModelMap.delete(e.getUnitId())})}_create(e){if(e==null)return;const t=e.getUnitId();this._setCurrent(t)}getAllModel(){return this._docViewModelMap}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var a;const t=this._currentUniverService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const s=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:s})}if(e===i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const s=(a=this._docViewModelMap.get(e))==null?void 0:a.docViewModel;if(s==null)return;s.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new O.DocumentViewModel(e)}},l.DocViewModelManagerService=st([rt(0,i.IUniverInstanceService)],l.DocViewModelManagerService);var ct=Object.defineProperty,lt=Object.getOwnPropertyDescriptor,dt=(o,n,e,t)=>{for(var a=t>1?void 0:t?lt(n,e):n,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(n,e,a):r(a))||a);return t&&a&&ct(n,e,a),a},ue=(o,n)=>(e,t)=>n(e,t,o);const ut=300;l.DocStateChangeManagerService=class extends i.RxDisposable{constructor(e,t,a){super();R(this,"_docStateChange$",new N.BehaviorSubject(null));R(this,"docStateChange$",this._docStateChange$.asObservable());R(this,"_stateCache",new Map);R(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=a,this._initialize()}setChangeState(e){const{trigger:t,noHistory:a}=e;t!=null&&(this._cacheChangeState(e),a||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===i.UndoCommandId||e.id===i.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const a=t.getUnitId();this._pushHistory(a)}}))}_cacheChangeState(e){const{trigger:t,unitId:a,noHistory:s}=e;if(!(t===i.RedoCommandId||t===i.UndoCommandId||s)){if(this._stateCache.has(a)){const r=this._stateCache.get(a);r==null||r.push(e)}else this._stateCache.set(a,[e]);t===z.id||t===V.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(a)},ut)):this._pushHistory(a)}}_pushHistory(e){const t=this._undoRedoService,a=this._stateCache.get(e);if(!Array.isArray(a)||a.length===0)return;const s=a.length,r=a[0].commandId,c=a[0],d=a[s-1],u={unitId:e,actions:a.reduce((g,S)=>i.TextX.compose(g,S.redoState.actions),[]),textRanges:d.redoState.textRanges},m={unitId:e,actions:a.reverse().reduce((g,S)=>i.TextX.compose(g,S.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:m}],redoMutations:[{id:r,params:u}]}),a.length=0}},l.DocStateChangeManagerService=dt([ue(0,b.Inject(i.IUndoRedoService)),ue(1,i.ICommandService),ue(2,i.IUniverInstanceService)],l.DocStateChangeManagerService);class k{constructor(){R(this,"_previousActiveRange",null);R(this,"_undoMutationParamsCache",[]);R(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:n=[],redoCache:e=[]}){this._undoMutationParamsCache=n,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(n){this._previousActiveRange=n}pushUndoRedoMutationParams(n,e){this._undoMutationParamsCache.push(n),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:n}=this._undoMutationParamsCache[0],e={unitId:n,actions:this._undoMutationParamsCache.reverse().reduce((a,s)=>i.TextX.compose(a,s.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:n,actions:this._redoMutationParamsCache.reduce((a,s)=>i.TextX.compose(a,s.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Te="doc.mutation.rich-text-editing",U={id:Te,type:i.CommandType.MUTATION,handler:(o,n)=>{var D;const{unitId:e,actions:t,textRanges:a,prevTextRanges:s,trigger:r,noHistory:c,isCompositionEnd:d,noNeedSetTextRange:u}=n,g=o.get(i.IUniverInstanceService).getUniverDocInstance(e),f=o.get(l.DocViewModelManagerService).getViewModel(e),p=o.get(l.TextSelectionManagerService),h=((D=p.getSelections())!=null?D:[]).map(F),I=o.get(l.DocStateChangeManagerService),_=o.get(k);if(g==null||f==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const M=!!g.getSnapshot().disabled;if(t.length===0||M)return{unitId:e,actions:[],textRanges:h};const T=g.apply(t),{segmentId:C}=t[0],E=g.getSelfOrHeaderFooterModel(C);f.getSelfOrHeaderFooterViewModel(C).reset(E),!u&&a&&r!=null&&queueMicrotask(()=>{p.replaceTextRanges(a)});const x={commandId:Te,unitId:e,trigger:r,noHistory:c,redoState:{actions:t,textRanges:a},undoState:{actions:T,textRanges:s!=null?s:h}};if(d){const y=_.fetchComposedUndoRedoMutationParams();if(y==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:B,redoMutationParams:P,previousActiveRange:re}=y;x.redoState.actions=P.actions,x.undoState.actions=B.actions,x.undoState.textRanges=[re]}return I.setChangeState(x),{unitId:e,actions:T,textRanges:h}}},z={id:"doc.command.insert-text",type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),{range:t,segmentId:a,body:s,unitId:r,textRanges:c}=n,{startOffset:d,collapsed:u}=t,m={id:U.id,params:{unitId:r,actions:[],textRanges:c}},g=new i.TextX;return u?d>0&&g.push({t:i.TextXActionType.RETAIN,len:d,segmentId:a}):g.push(...de(t,a)),g.push({t:i.TextXActionType.INSERT,body:s,len:s.dataStream.length,line:0,segmentId:a}),m.params.actions=g.serialize(),!!e.syncExecuteCommand(m.id,m.params)}};var L=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(L||{});const V={id:"doc.command.delete-text",type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),{range:t,segmentId:a,unitId:s,direction:r,textRanges:c,len:d=1}=n,{startOffset:u}=t,m={id:U.id,params:{unitId:s,actions:[],textRanges:c}},g=new i.TextX;return u>0&&g.push({t:i.TextXActionType.RETAIN,len:r===0?u-d:u,segmentId:a}),g.push({t:i.TextXActionType.DELETE,len:d,line:0,segmentId:a}),m.params.actions=g.serialize(),!!e.syncExecuteCommand(m.id,m.params)}},me={id:"doc.command.update-text",type:i.CommandType.COMMAND,handler:async(o,n)=>{const{range:e,segmentId:t,updateBody:a,coverType:s,unitId:r,textRanges:c}=n,d=o.get(i.ICommandService),u={id:U.id,params:{unitId:r,actions:[],textRanges:c}},m=new i.TextX,{startOffset:g,endOffset:S}=e;return m.push({t:i.TextXActionType.RETAIN,len:g,segmentId:t}),m.push({t:i.TextXActionType.RETAIN,body:a,len:S-g,segmentId:t,coverType:s}),u.params.actions=m.serialize(),!!d.syncExecuteCommand(u.id,u.params)}};function mt(o,n){const e=[];for(let t=0,a=o.length;t<a;t++)o[t]===i.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(n)for(const t of e)n.bullet&&(t.bullet=i.Tools.deepClone(n.bullet)),n.paragraphStyle&&(t.paragraphStyle=i.Tools.deepClone(n.paragraphStyle));return e}const ye={id:"doc.command.break-line",type:i.CommandType.COMMAND,handler:async o=>{var p,v;const n=o.get(l.TextSelectionManagerService),e=o.get(i.IUniverInstanceService),t=o.get(i.ICommandService),a=n.getActiveRange();if(a==null)return!1;const s=e.getCurrentUniverDocInstance(),r=s.getUnitId(),{startOffset:c,segmentId:d,style:u}=a,m=[{startOffset:c+1,endOffset:c+1,style:u}],S=((v=(p=s.getBody())==null?void 0:p.paragraphs)!=null?v:[]).find(h=>h.startIndex>=c);return await t.executeCommand(z.id,{unitId:r,body:{dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:mt(i.DataStreamTreeTokenType.PARAGRAPH,S)},range:a,textRanges:m,segmentId:d})}};var gt=Object.defineProperty,St=Object.getOwnPropertyDescriptor,ft=(o,n,e,t)=>{for(var a=t>1?void 0:t?St(n,e):n,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(n,e,a):r(a))||a);return t&&a&>(n,e,a),a},ge=(o,n)=>(e,t)=>n(e,t,o);l.DocSkeletonManagerService=class extends i.RxDisposable{constructor(e,t,a){super();R(this,"_currentSkeletonUnitId","");R(this,"_docSkeletonMap",new Map);R(this,"_currentSkeleton$",new N.BehaviorSubject(null));R(this,"currentSkeleton$",this._currentSkeleton$.asObservable());R(this,"_currentSkeletonBefore$",new N.BehaviorSubject(null));R(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._currentUniverService=a,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._currentUniverService.docDisposed$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=this._currentUniverService.getCurrentUniverDocInstance().getUnitId()})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const a=this.getSkeletonByUnitId(e);a!=null&&(a.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const a=this.getSkeletonByUnitId(t);a.skeleton.calculate(),a.dirty=!0}else{const a=this._buildSkeleton(e.docViewModel);a.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:a,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return O.DocumentSkeleton.create(e,this._localeService)}},l.DocSkeletonManagerService=ft([ge(0,b.Inject(i.LocaleService)),ge(1,b.Inject(l.DocViewModelManagerService)),ge(2,i.IUniverInstanceService)],l.DocSkeletonManagerService);const ht={id:"doc.command.inner-paste",type:i.CommandType.COMMAND,handler:async(o,n)=>{const{segmentId:e,body:t,textRanges:a}=n,s=o.get(i.ICommandService),r=o.get(l.TextSelectionManagerService),c=o.get(i.IUniverInstanceService),d=r.getSelections();if(!Array.isArray(d)||d.length===0)return!1;const m=c.getCurrentUniverDocInstance().getUnitId(),g={id:U.id,params:{unitId:m,actions:[],textRanges:a}},S=new i.MemoryCursor;S.reset();const f=new i.TextX;for(const v of d){const{startOffset:h,endOffset:I,collapsed:_}=v,M=h-S.cursor;_?f.push({t:i.TextXActionType.RETAIN,len:M,segmentId:e}):f.push(...de(v,e,S.cursor)),f.push({t:i.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!s.syncExecuteCommand(g.id,g.params)}},Se={id:"doc.command.inner-cut",type:i.CommandType.COMMAND,handler:async(o,n)=>{const{segmentId:e,textRanges:t}=n,a=o.get(i.ICommandService),s=o.get(l.TextSelectionManagerService),r=o.get(i.IUniverInstanceService),c=s.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const d=r.getCurrentUniverDocInstance().getUnitId(),u=r.getUniverDocInstance(d),m=i.getDocsUpdateBody(u.snapshot,e);if(m==null)return!1;const g={id:U.id,params:{unitId:d,actions:[],textRanges:t}},S=new i.MemoryCursor;S.reset();const f=new i.TextX;for(const v of c){const{startOffset:h,endOffset:I,collapsed:_}=v,M=h-S.cursor;_?f.push({t:i.TextXActionType.RETAIN,len:M,segmentId:e}):f.push(...vt(v,m,e,S.cursor)),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!a.syncExecuteCommand(g.id,g.params)}};function vt(o,n,e="",t=0){const{startOffset:a,endOffset:s}=o,r=[],{paragraphs:c=[]}=n,d=a-t,u=s-t,m=c==null?void 0:c.find(g=>g.startIndex-t>=d&&g.startIndex-t<=u);if(d>0&&r.push({t:i.TextXActionType.RETAIN,len:d,segmentId:e}),m&&m.startIndex-t>d){const g=m.startIndex-t;r.push({t:i.TextXActionType.DELETE,len:g-d,line:0,segmentId:e}),r.push({t:i.TextXActionType.RETAIN,len:1,segmentId:e}),u>g+1&&r.push({t:i.TextXActionType.DELETE,len:u-g-1,line:0,segmentId:e})}else r.push({t:i.TextXActionType.DELETE,len:u-d,line:0,segmentId:e});return r}const Re={id:"doc.command.delete-left",type:i.CommandType.COMMAND,handler:async o=>{var T;const n=o.get(l.TextSelectionManagerService),e=o.get(l.DocSkeletonManagerService),t=o.get(i.IUniverInstanceService),a=o.get(i.ICommandService),s=n.getActiveRange(),r=n.getSelections(),c=(T=e.getCurrent())==null?void 0:T.skeleton;let d=!0;if(s==null||c==null||r==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:m,collapsed:g,segmentId:S,style:f}=s,p=c.findNodeByCharIndex(m),v=O.hasListGlyph(p),h=O.isIndentByGlyph(p,u.getBody());let I=m;const _=c.findNodeByCharIndex(m-1);if(O.isFirstGlyph(p)&&_!==p&&(v===!0||h===!0)){const C=O.getParagraphByGlyph(p,u.getBody());if(C==null)return!1;const E=C==null?void 0:C.startIndex,A={startIndex:0},x=C.paragraphStyle;if(v===!0){const y=C.paragraphStyle;y&&(A.paragraphStyle=y)}else if(h===!0){const y=C.bullet;y&&(A.bullet=y),x!=null&&(A.paragraphStyle={...x},delete A.paragraphStyle.hanging,delete A.paragraphStyle.indentStart)}const D=[{startOffset:I,endOffset:I,style:f}];d=await a.executeCommand(me.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...A}]},range:{startOffset:E,endOffset:E+1},textRanges:D,coverType:i.UpdateDocsAttributeType.REPLACE,segmentId:S})}else if(g===!0){if(_==null)return!0;if(_.content==="\r")d=await a.executeCommand(fe.id,{direction:L.LEFT,range:s});else{I-=_.count;const C=[{startOffset:I,endOffset:I,style:f}];d=await a.executeCommand(V.id,{unitId:u.getUnitId(),range:s,segmentId:S,direction:L.LEFT,len:_.count,textRanges:C})}}else{const C=xe(s,r);d=await a.executeCommand(Se.id,{segmentId:S,textRanges:C})}return d}},Oe={id:"doc.command.delete-right",type:i.CommandType.COMMAND,handler:async o=>{var p;const n=o.get(l.TextSelectionManagerService),e=o.get(l.DocSkeletonManagerService),t=o.get(i.IUniverInstanceService),a=o.get(i.ICommandService),s=n.getActiveRange(),r=n.getSelections(),c=(p=e.getCurrent())==null?void 0:p.skeleton;let d;if(s==null||c==null||r==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:m,collapsed:g,segmentId:S,style:f}=s;if(m===u.getBody().dataStream.length-2&&g)return!0;if(g===!0){const v=c.findNodeByCharIndex(m);if(v.content==="\r")d=await a.executeCommand(fe.id,{direction:L.RIGHT,range:s});else{const h=[{startOffset:m,endOffset:m,style:f}];d=await a.executeCommand(V.id,{unitId:u.getUnitId(),range:s,segmentId:S,direction:L.RIGHT,textRanges:h,len:v.count})}}else{const v=xe(s,r);d=await a.executeCommand(Se.id,{segmentId:S,textRanges:v})}return d}},fe={id:"doc.command.merge-two-paragraph",type:i.CommandType.COMMAND,handler:async(o,n)=>{var A,x,D;const e=o.get(l.TextSelectionManagerService),t=o.get(i.IUniverInstanceService),a=o.get(i.ICommandService),{direction:s,range:r}=n,c=e.getActiveRange(),d=e.getSelections();if(c==null||d==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:m,collapsed:g,segmentId:S,style:f}=c;if(!g)return!1;const p=s===L.LEFT?m:m+1,v=(D=(x=(A=u.getBody())==null?void 0:A.paragraphs)==null?void 0:x.find(y=>y.startIndex>=p))==null?void 0:D.startIndex,h=pt(u.getBody(),p,v),I=s===L.LEFT?m-1:m,_=u.getUnitId(),M=[{startOffset:I,endOffset:I,style:f}],T={id:U.id,params:{unitId:_,actions:[],textRanges:M,prevTextRanges:[r]}},C=new i.TextX;return C.push({t:i.TextXActionType.RETAIN,len:s===L.LEFT?m-1:m,segmentId:S}),h.dataStream.length&&C.push({t:i.TextXActionType.INSERT,body:h,len:h.dataStream.length,line:0,segmentId:S}),C.push({t:i.TextXActionType.RETAIN,len:1,segmentId:S}),C.push({t:i.TextXActionType.DELETE,len:v+1-p,line:0,segmentId:S}),T.params.actions=C.serialize(),!!a.syncExecuteCommand(T.id,T.params)}};function pt(o,n,e){const{textRuns:t}=o,a=o.dataStream.substring(n,e);if(t==null)return{dataStream:a};const s=[];for(const r of t){const{st:c,ed:d}=r;d<=n||c>=e||(c<n?s.push({...r,st:0,ed:d-n}):d>e?s.push({...r,st:c-n,ed:e-n}):s.push({...r,st:c-n,ed:d-n}))}return{dataStream:a,textRuns:s}}function xe(o,n){let e=o.endOffset;for(const a of n){const{startOffset:s,endOffset:r}=a;s==null||r==null||r<=o.endOffset&&(e-=r-s)}return[{startOffset:e,endOffset:e,style:o.style}]}const he={id:"doc.command.ime-input",type:i.CommandType.COMMAND,handler:async(o,n)=>{const{unitId:e,newText:t,oldTextLen:a,isCompositionEnd:s,isCompositionStart:r}=n,c=o.get(i.ICommandService),d=o.get(k),u=d.getActiveRange();if(u==null)return!1;const{startOffset:m,style:g,segmentId:S}=u,f=t.length,p=[{startOffset:m+f,endOffset:m+f,collapsed:!0,style:g}],v={id:U.id,params:{unitId:e,actions:[],textRanges:p}},h=new i.TextX;!u.collapsed&&r?h.push(...de(u,S)):h.push({t:i.TextXActionType.RETAIN,len:m,segmentId:S}),a>0&&h.push({t:i.TextXActionType.DELETE,len:a,line:0,segmentId:S}),h.push({t:i.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:S}),v.params.actions=h.serialize(),v.params.noHistory=!s,v.params.isCompositionEnd=s;const I=c.syncExecuteCommand(v.id,v.params);return d.pushUndoRedoMutationParams(I,v.params),!!I}};function w(o,n,e,t){var s;const{segmentId:a}=(s=e.getActiveRange())!=null?s:{};return a==null?!1:t.executeCommand(ve.id,{segmentId:a,preCommandId:o,...n!=null?n:{}})}const De="doc.command.set-inline-format-bold",W={id:De,type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),t=o.get(l.TextSelectionManagerService);return w(De,n,t,e)}},Ee="doc.command.set-inline-format-italic",Z={id:Ee,type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),t=o.get(l.TextSelectionManagerService);return w(Ee,n,t,e)}},Ae="doc.command.set-inline-format-underline",q={id:Ae,type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),t=o.get(l.TextSelectionManagerService);return w(Ae,n,t,e)}},Ue="doc.command.set-inline-format-strikethrough",J={id:Ue,type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),t=o.get(l.TextSelectionManagerService);return w(Ue,n,t,e)}},Ne="doc.command.set-inline-format-subscript",$={id:Ne,type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),t=o.get(l.TextSelectionManagerService);return w(Ne,n,t,e)}},be="doc.command.set-inline-format-superscript",K={id:be,type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),t=o.get(l.TextSelectionManagerService);return w(be,n,t,e)}},Pe="doc.command.set-inline-format-fontsize",Q={id:Pe,type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),t=o.get(l.TextSelectionManagerService);return w(Pe,n,t,e)}},we="doc.command.set-inline-format-font-family",ee={id:we,type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),t=o.get(l.TextSelectionManagerService);return w(we,n,t,e)}},Le="doc.command.set-inline-format-text-color",te={id:Le,type:i.CommandType.COMMAND,handler:async(o,n)=>{const e=o.get(i.ICommandService),t=o.get(l.TextSelectionManagerService);return w(Le,n,t,e)}},Be={[W.id]:"bl",[Z.id]:"it",[q.id]:"ul",[J.id]:"st",[Q.id]:"fs",[ee.id]:"ff",[te.id]:"cl",[$.id]:"va",[K.id]:"va"},ve={id:"doc.command.set-inline-format",type:i.CommandType.COMMAND,handler:async(o,n)=>{const{segmentId:e,value:t,preCommandId:a}=n,s=o.get(i.ICommandService),r=o.get(l.TextSelectionManagerService),c=o.get(i.IUniverInstanceService),d=r.getSelections();if(!Array.isArray(d)||d.length===0)return!1;let u=c.getCurrentUniverDocInstance(),m=u.getUnitId();m===i.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=c.getUniverDocInstance(i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),m=u.getUnitId());let g;switch(a){case W.id:case Z.id:case q.id:case J.id:case $.id:case K.id:{g=_t(u.getBody().textRuns,a,d);break}case Q.id:case ee.id:{g=t;break}case te.id:{g={rgb:t};break}default:throw new Error(`Unknown command: ${a} in handleInlineFormat`)}const S={id:U.id,params:{unitId:m,actions:[],textRanges:d.map(F)}},f=new i.TextX,p=new i.MemoryCursor;p.reset();for(const h of d){const{startOffset:I,endOffset:_}=h,M={dataStream:"",textRuns:[{st:0,ed:_-I,ts:{[Be[a]]:g}}]},T=I-p.cursor;T!==0&&f.push({t:i.TextXActionType.RETAIN,len:T,segmentId:e}),f.push({t:i.TextXActionType.RETAIN,body:M,len:_-I,segmentId:e}),p.reset(),p.moveCursor(_)}return S.params.actions=f.serialize(),!!s.syncExecuteCommand(S.id,S.params)}};function It(o){return o!==null&&typeof o=="object"}function _t(o,n,e){let t=0,a=0;const s=Be[n];for(;t!==o.length&&a!==e.length;){const{startOffset:r,endOffset:c}=e[a],{st:d,ed:u,ts:m}=o[t];if(c<=d)a++;else if(u<=r)t++;else{if(/bl|it/.test(s))return(m==null?void 0:m[s])===i.BooleanNumber.TRUE?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE;if(/ul|st/.test(s))return It(m==null?void 0:m[s])&&(m==null?void 0:m[s]).s===i.BooleanNumber.TRUE?{s:i.BooleanNumber.FALSE}:{s:i.BooleanNumber.TRUE};if(/va/.test(s))return n===$.id?(m==null?void 0:m[s])===i.BaselineOffset.SUBSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUBSCRIPT:(m==null?void 0:m[s])===i.BaselineOffset.SUPERSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(s)?i.BooleanNumber.TRUE:/ul|st/.test(s)?{s:i.BooleanNumber.TRUE}:n===$.id?i.BaselineOffset.SUBSCRIPT:i.BaselineOffset.SUPERSCRIPT}const pe={id:"doc.command.list-operation",type:i.CommandType.COMMAND,handler:(o,n)=>{var C,E,A;const e=o.get(l.TextSelectionManagerService),t=o.get(i.IUniverInstanceService),a=o.get(i.ICommandService),{listType:s}=n,r=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),d=(C=e.getSelections())!=null?C:[],u=(E=r.getBody())==null?void 0:E.paragraphs,m=d.map(F);if(c==null||u==null)return!1;const g=Xe(c,u),{segmentId:S}=c,f=r.getUnitId(),p=g.every(x=>{var D;return((D=x.bullet)==null?void 0:D.listType)===s});let h=i.Tools.generateRandomId(6);if(g.length===1){const x=u.indexOf(g[0]),D=u[x-1],y=u[x+1];D&&D.bullet&&D.bullet.listType===s?h=D.bullet.listId:y&&y.bullet&&y.bullet.listType===s&&(h=y.bullet.listId)}const I={id:U.id,params:{unitId:f,actions:[],textRanges:m}},_=new i.MemoryCursor;_.reset();const M=new i.TextX;for(const x of g){const{startIndex:D}=x;M.push({t:i.TextXActionType.RETAIN,len:D-_.cursor,segmentId:S});const y={...x.paragraphStyle,hanging:void 0,indentStart:void 0};M.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[p?{paragraphStyle:y,startIndex:0}:{...x,startIndex:0,bullet:{...(A=x.bullet)!=null?A:{nestingLevel:0,textStyle:{fs:20}},listType:s,listId:h}}]},segmentId:S,coverType:i.UpdateDocsAttributeType.REPLACE}),_.moveCursorTo(D+1)}return I.params.actions=M.serialize(),!!a.syncExecuteCommand(I.id,I.params)}},Fe={id:"doc.command.bullet-list",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{listType:i.PresetListType.BULLET_LIST})},$e={id:"doc.command.order-list",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{listType:i.PresetListType.ORDER_LIST})};function Xe(o,n){const{startOffset:e,endOffset:t}=o,a=[];let s=-1;for(const r of n){const{startIndex:c}=r;(e>s&&e<=c||t>s&&t<=c||c>=e&&c<=t)&&a.push(r),s=c}return a}const X={id:"doc.command.align-operation",type:i.CommandType.COMMAND,handler:(o,n)=>{var M,T;const e=o.get(l.TextSelectionManagerService),t=o.get(i.IUniverInstanceService),a=o.get(i.ICommandService),{alignType:s}=n,r=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),d=(M=e.getSelections())!=null?M:[],u=(T=r.getBody())==null?void 0:T.paragraphs,m=d.map(F);if(c==null||u==null)return!1;const g=Xe(c,u),{segmentId:S}=c,f=r.getUnitId(),p=g.every(C=>{var E;return((E=C.paragraphStyle)==null?void 0:E.horizontalAlign)===s}),v={id:U.id,params:{unitId:f,actions:[],textRanges:m}},h=new i.MemoryCursor;h.reset();const I=new i.TextX;for(const C of g){const{startIndex:E}=C;I.push({t:i.TextXActionType.RETAIN,len:E-h.cursor,segmentId:S});const A={...C.paragraphStyle,horizontalAlign:p?i.HorizontalAlign.UNSPECIFIED:s};I.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...C,paragraphStyle:A,startIndex:0}]},segmentId:S,coverType:i.UpdateDocsAttributeType.REPLACE}),h.moveCursorTo(E+1)}return v.params.actions=I.serialize(),!!a.syncExecuteCommand(v.id,v.params)}},ke={id:"doc.command.align-left",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(X.id,{alignType:i.HorizontalAlign.LEFT})},ze={id:"doc.command.align-center",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(X.id,{alignType:i.HorizontalAlign.CENTER})},Ve={id:"doc.command.align-right",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(X.id,{alignType:i.HorizontalAlign.RIGHT})},je={id:"doc.command.align-justify",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(X.id,{alignType:i.HorizontalAlign.JUSTIFIED})},He={id:"doc.command-replace-content",type:i.CommandType.COMMAND,handler:async(o,n)=>{var f;const{unitId:e,body:t,textRanges:a,segmentId:s=""}=n,r=o.get(i.IUniverInstanceService),c=o.get(i.ICommandService),d=o.get(l.TextSelectionManagerService),u=(f=r.getUniverDocInstance(e))==null?void 0:f.getSnapshot().body,m=d.getSelections();if(u==null||!Array.isArray(m)||m.length===0)return!1;const g=Ye(e,s,u,t);return g.params.textRanges=a,!!c.syncExecuteCommand(g.id,g.params)}},Ge={id:"doc.command-cover-content",type:i.CommandType.COMMAND,handler:async(o,n)=>{var m;const{unitId:e,body:t,segmentId:a=""}=n,s=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),c=o.get(i.IUndoRedoService),d=(m=s.getUniverDocInstance(e))==null?void 0:m.getSnapshot().body;if(d==null)return!1;const u=Ye(e,a,d,t);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,r.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function Ye(o,n,e,t){const a={id:U.id,params:{unitId:o,actions:[],textRanges:[]}},s=new i.TextX,r=(e==null?void 0:e.dataStream.length)-2;return r>0&&s.push({t:i.TextXActionType.DELETE,len:r,line:0,segmentId:n}),t.dataStream.length>0&&s.push({t:i.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:n}),a.params.actions=s.serialize(),a}const ne={id:"doc.operation.move-cursor",type:i.CommandType.OPERATION,handler:(o,n)=>!!n},ie={id:"doc.operation.move-selection",type:i.CommandType.OPERATION,handler:(o,n)=>!!n},Ct=(o,n)=>{const e=o.get(i.IUniverInstanceService).getUniverDocInstance(n.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...i.Tools.deepClone(n),zoomRatio:t}},j={id:"doc.operation.set-zoom-ratio",type:i.CommandType.OPERATION,handler:(o,n)=>{const e=o.get(i.IUniverInstanceService).getUniverDocInstance(n.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:n.zoomRatio}:t.settings.zoomRatio=n.zoomRatio,!0}},We={type:i.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,n)=>{var g,S;const e=o.get(i.ICommandService),t=o.get(i.IUndoRedoService),a=o.get(i.IUniverInstanceService);let s=a.getCurrentUniverDocInstance().getUnitId(),r=1;if(n&&(s=(g=n.documentId)!=null?g:s,r=(S=n.zoomRatio)!=null?S:r),!a.getUniverDocInstance(s))return!1;const d={zoomRatio:r,unitId:s},u=Ct(o,d);return e.syncExecuteCommand(j.id,d)?(t.pushUndoRedo({unitID:s,undoMutations:[{id:j.id,params:u}],redoMutations:[{id:j.id,params:d}]}),!0):!1}},Ze={id:"doc.operation.select-all",type:i.CommandType.COMMAND,handler:async o=>{const n=o.get(i.IUniverInstanceService),e=o.get(l.TextSelectionManagerService),t=n.getCurrentUniverDocInstance().getSnapshot().body;if(t==null)return!1;const a=[{startOffset:0,endOffset:t.dataStream.length-2}];return e.replaceTextRanges(a,!1),!0}};var Mt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,yt=(o,n,e,t)=>{for(var a=t>1?void 0:t?Tt(n,e):n,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(n,e,a):r(a))||a);return t&&a&&Mt(n,e,a),a},H=(o,n)=>(e,t)=>n(e,t,o);let ae=class extends i.Disposable{constructor(n,e,t,a,s){super();R(this,"_previousIMEContent","");R(this,"_isCompositionStart",!0);R(this,"_onStartSubscription");R(this,"_onUpdateSubscription");R(this,"_onEndSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=a,this._commandService=s,this._initialize()}dispose(){var n,e,t;(n=this._onStartSubscription)==null||n.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(t=this._onEndSubscription)==null||t.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(n=>{if(n==null)return;this._resetIME();const{activeRange:e}=n;e!=null&&this._imeInputManagerService.setActiveRange(i.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async n=>{this._updateContent(n,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(n=>{this._updateContent(n,!1)})}async _updateContent(n,e){var u;const t=(u=this._docSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(n==null||t==null)return;const a=this._currentUniverService.getCurrentUniverDocInstance(),{event:s,activeRange:r}=n;if(t==null||r==null)return;const d=s.data;d===this._previousIMEContent&&e||(await this._commandService.executeCommand(he.id,{unitId:a.getUnitId(),newText:d,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=d):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};ae=yt([i.OnLifecycle(i.LifecycleStages.Rendered,ae),H(0,b.Inject(l.DocSkeletonManagerService)),H(1,i.IUniverInstanceService),H(2,O.ITextSelectionRenderManager),H(3,b.Inject(k)),H(4,i.ICommandService)],ae);var Rt=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,xt=(o,n,e,t)=>{for(var a=t>1?void 0:t?Ot(n,e):n,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(n,e,a):r(a))||a);return t&&a&&Rt(n,e,a),a},G=(o,n)=>(e,t)=>n(e,t,o);let oe=class extends i.Disposable{constructor(n,e,t,a,s){super();R(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionManagerService=a,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe()}_initialize(){}_commandExecutedListener(){const n=[ne.id,ie.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!n.includes(e.id))return;const t=e.params;switch(e.id){case ne.id:return this._handleMoveCursor(t.direction);case ie.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(n){var v,h,I;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._currentUniverService.getCurrentUniverDocInstance(),s=(v=this._docSkeletonManagerService.getCurrent())==null?void 0:v.skeleton,r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:c,endOffset:d,style:u,collapsed:m,direction:g}=e;if(t.length>1){let _=Number.POSITIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(const T of t)_=Math.min(_,T.startOffset),M=Math.max(M,T.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:n===i.Direction.LEFT||n===i.Direction.UP?M:_,endOffset:n===i.Direction.LEFT||n===i.Direction.UP?_:M,style:u}],!1);return}const S=m||g===O.RANGE_DIRECTION.FORWARD?c:d;let f=m||g===O.RANGE_DIRECTION.FORWARD?d:c;const p=(h=a.getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(n===i.Direction.LEFT||n===i.Direction.RIGHT){const _=s.findNodeByCharIndex(f-1),M=s.findNodeByCharIndex(f);f=n===i.Direction.RIGHT?f+M.count:f-((I=_==null?void 0:_.count)!=null?I:0),f=Math.min(p-2,Math.max(0,f)),this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:f,style:u}],!1)}else{const _=s.findNodeByCharIndex(f),M=r.document.getOffsetConfig(),T=this._getTopOrBottomPosition(s,_,n===i.Direction.DOWN);if(T==null){const E=n===i.Direction.UP?0:p-2;if(E===f)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:E,style:u}],!1);return}const C=new O.NodePositionConvertToCursor(M,s).getRangePointData(T,T).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:C.endOffset,style:u}],!1)}}_handleMoveCursor(n){var S,f,p;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._currentUniverService.getCurrentUniverDocInstance(),s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,r=this._getDocObject();if(e==null||s==null||r==null||t==null)return;const{startOffset:c,endOffset:d,style:u,collapsed:m}=e,g=(f=a.getBody().dataStream.length)!=null?f:Number.POSITIVE_INFINITY;if(n===i.Direction.LEFT||n===i.Direction.RIGHT){let v;if(!e.collapsed||t.length>1){let h=Number.POSITIVE_INFINITY,I=Number.NEGATIVE_INFINITY;for(const _ of t)h=Math.min(h,_.startOffset),I=Math.max(I,_.endOffset);v=n===i.Direction.LEFT?h:I}else{const h=s.findNodeByCharIndex(c-1),I=s.findNodeByCharIndex(c);n===i.Direction.LEFT?v=Math.max(0,c-((p=h==null?void 0:h.count)!=null?p:0)):v=Math.min(g-2,d+I.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:v,endOffset:v,style:u}],!1)}else{const v=s.findNodeByCharIndex(c),h=s.findNodeByCharIndex(d),I=r.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,n===i.Direction.UP?v:h,n===i.Direction.DOWN);if(_==null){let T;m?T=n===i.Direction.UP?0:g-2:T=n===i.Direction.UP?c:d,this._textSelectionManagerService.replaceTextRanges([{startOffset:T,endOffset:T,style:u}],!1);return}const M=new O.NodePositionConvertToCursor(I,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...M,style:u}],!1)}}_getTopOrBottomPosition(n,e,t){if(e==null)return;const a=this._getSpanLeftOffsetInLine(e),s=this._getNextOrPrevLine(e,t);if(s==null)return;const r=this._matchPositionByLeftOffset(n,s,a);if(r!=null)return{...r,isBack:!0}}_getSpanLeftOffsetInLine(n){const e=n.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:a}=n;return t+a}_matchPositionByLeftOffset(n,e,t){const a={distance:Number.POSITIVE_INFINITY};for(const s of e.divides){const r=s.left;for(const c of s.glyphGroup){const{left:d}=c,u=r+d,m=Math.abs(t-u);m<a.distance&&(a.glyph=c,a.distance=m)}}if(a.glyph!=null)return n.findPositionByGlyph(a.glyph)}_getNextOrPrevLine(n,e){var p,v,h,I,_,M,T,C,E,A,x,D;const t=n.parent;if(t==null)return;const a=t.parent;if(a==null)return;const s=a.parent;if(s==null)return;const r=s.lines.indexOf(a);if(r===-1)return;let c;if(e===!0?c=s.lines[r+1]:c=s.lines[r-1],c!=null)return c;const d=s.parent;if(d==null)return;const u=d.columns.indexOf(s);if(u===-1)return;if(e===!0)c=(p=d.columns[u+1])==null?void 0:p.lines[0];else{const y=(h=(v=d.columns)==null?void 0:v[u-1])==null?void 0:h.lines;c=y==null?void 0:y[y.length-1]}if(c!=null)return c;const m=d.parent;if(m==null)return;const g=m.sections.indexOf(d);if(g===-1)return;if(e===!0)c=(_=(I=m.sections[g-1])==null?void 0:I.columns[0])==null?void 0:_.lines[0];else{const y=(T=(M=m.sections)==null?void 0:M[g-1])==null?void 0:T.columns,B=y==null?void 0:y[y.length-1],P=B==null?void 0:B.lines;c=P==null?void 0:P[P.length-1]}if(c!=null)return c;const S=m.parent;if(S==null)return;const f=S.pages.indexOf(m);if(f!==-1){if(e===!0)c=(A=(E=(C=S.pages[f+1])==null?void 0:C.sections[0])==null?void 0:E.columns[0])==null?void 0:A.lines[0];else{const y=(x=S.pages[f-1])==null?void 0:x.sections;if(y==null)return;const B=(D=y[y.length-1])==null?void 0:D.columns,P=B[B.length-1],re=P==null?void 0:P.lines;c=re[re.length-1]}if(c!=null)return c}}_getDocObject(){return ce(this._currentUniverService,this._renderManagerService)}};oe=xt([i.OnLifecycle(i.LifecycleStages.Rendered,oe),G(0,b.Inject(l.DocSkeletonManagerService)),G(1,i.IUniverInstanceService),G(2,O.IRenderManagerService),G(3,b.Inject(l.TextSelectionManagerService)),G(4,i.ICommandService)],oe);var Dt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,At=(o,n,e,t)=>{for(var a=t>1?void 0:t?Et(n,e):n,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(n,e,a):r(a))||a);return t&&a&&Dt(n,e,a),a},Y=(o,n)=>(e,t)=>n(e,t,o);let se=class extends i.Disposable{constructor(n,e,t,a,s){super();R(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionRenderManager=a,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async n=>{var p;if(n==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:a,content:s="",activeRange:r}=n,c=a,d=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(c.data==null||d==null||!d||!r)return;const{startOffset:u,segmentId:m,style:g}=r,S=s.length,f=[{startOffset:u+S,endOffset:u+S,style:g}];await this._commandService.executeCommand(z.id,{unitId:t,body:{dataStream:s},range:r,textRanges:f,segmentId:m})})}_commandExecutedListener(){}_getDocObject(){return ce(this._currentUniverService,this._renderManagerService)}};se=At([i.OnLifecycle(i.LifecycleStages.Rendered,se),Y(0,b.Inject(l.DocSkeletonManagerService)),Y(1,i.IUniverInstanceService),Y(2,O.IRenderManagerService),Y(3,O.ITextSelectionRenderManager),Y(4,i.ICommandService)],se);var Ut=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,bt=(o,n,e,t)=>{for(var a=t>1?void 0:t?Nt(n,e):n,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(n,e,a):r(a))||a);return t&&a&&Ut(n,e,a),a},Pt=(o,n)=>(e,t)=>n(e,t,o);const wt={hasScroll:!0},Lt="docs";l.UniverDocsPlugin=(Ie=class extends i.Plugin{constructor(e={},t){super(Lt);R(this,"_config");this._injector=t,this._config=Object.assign(wt,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[ne,ie,Re,Oe,W,Z,q,J,$,K,Q,ee,te,ve,ye,z,V,me,he,fe,U,He,Ge,We,j,le,Ze,$e,Fe,pe,ke,ze,Ve,X,je].forEach(e=>{this._injector.get(i.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[l.DocSkeletonManagerService],[l.DocViewModelManagerService],[l.DocStateChangeManagerService],[k],[O.ITextSelectionRenderManager,{useClass:O.TextSelectionRenderManager}],[l.TextSelectionManagerService],[se],[ae],[oe]].forEach(t=>e.add(t))}},R(Ie,"type",i.PluginType.Doc),Ie),l.UniverDocsPlugin=bt([Pt(1,b.Inject(b.Injector))],l.UniverDocsPlugin),l.AlignCenterCommand=ze,l.AlignJustifyCommand=je,l.AlignLeftCommand=ke,l.AlignOperationCommand=X,l.AlignRightCommand=Ve,l.BreakLineCommand=ye,l.BulletListCommand=Fe,l.CoverContentCommand=Ge,l.CutContentCommand=Se,l.DOCS_COMPONENT_DEFAULT_Z_INDEX=Qe,l.DOCS_COMPONENT_HEADER_LAYER_INDEX=Ke,l.DOCS_COMPONENT_MAIN_LAYER_INDEX=Je,l.DOCS_VIEW_KEY=_e,l.DeleteCommand=V,l.DeleteLeftCommand=Re,l.DeleteRightCommand=Oe,l.IMEInputCommand=he,l.IMEInputManagerService=k,l.InnerPasteCommand=ht,l.InsertCommand=z,l.MoveCursorOperation=ne,l.MoveSelectionOperation=ie,l.NORMAL_TEXT_SELECTION_PLUGIN_NAME=et,l.OrderListCommand=$e,l.ReplaceContentCommand=He,l.RichTextEditingMutation=U,l.SelectAllOperation=Ze,l.SetDocZoomRatioCommand=We,l.SetDocZoomRatioOperation=j,l.SetInlineFormatBoldCommand=W,l.SetInlineFormatCommand=ve,l.SetInlineFormatFontFamilyCommand=ee,l.SetInlineFormatFontSizeCommand=Q,l.SetInlineFormatItalicCommand=Z,l.SetInlineFormatStrikethroughCommand=J,l.SetInlineFormatSubscriptCommand=$,l.SetInlineFormatSuperscriptCommand=K,l.SetInlineFormatTextColorCommand=te,l.SetInlineFormatUnderlineCommand=q,l.SetTextSelectionsOperation=le,l.UpdateCommand=me,l.VIEWPORT_KEY=Ce,l.getDocObject=ce,l.getDocObjectById=qe,l.serializeTextRange=F,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet normal base-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"bugs": {
|
|
18
18
|
"url": "https://github.com/dream-num/univer/issues"
|
|
19
19
|
},
|
|
20
|
-
"keywords": [
|
|
20
|
+
"keywords": [
|
|
21
|
+
"univer"
|
|
22
|
+
],
|
|
21
23
|
"exports": {
|
|
22
24
|
".": {
|
|
23
25
|
"import": "./lib/es/index.js",
|
|
@@ -50,20 +52,19 @@
|
|
|
50
52
|
"peerDependencies": {
|
|
51
53
|
"@wendellhu/redi": "0.13.0",
|
|
52
54
|
"rxjs": ">=7.0.0",
|
|
53
|
-
"@univerjs/core": "0.1.
|
|
54
|
-
"@univerjs/engine-render": "0.1.
|
|
55
|
+
"@univerjs/core": "0.1.4",
|
|
56
|
+
"@univerjs/engine-render": "0.1.4"
|
|
55
57
|
},
|
|
56
58
|
"dependencies": {},
|
|
57
59
|
"devDependencies": {
|
|
58
60
|
"@wendellhu/redi": "^0.13.0",
|
|
59
|
-
"less": "^4.2.0",
|
|
60
61
|
"rxjs": "^7.8.1",
|
|
61
62
|
"typescript": "^5.4.2",
|
|
62
63
|
"vite": "^5.1.6",
|
|
63
|
-
"vitest": "^1.
|
|
64
|
-
"@univerjs/
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/
|
|
64
|
+
"vitest": "^1.4.0",
|
|
65
|
+
"@univerjs/core": "0.1.4",
|
|
66
|
+
"@univerjs/engine-render": "0.1.4",
|
|
67
|
+
"@univerjs/shared": "0.1.4"
|
|
67
68
|
},
|
|
68
69
|
"scripts": {
|
|
69
70
|
"test": "vitest run",
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2023-present DreamNum Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { Disposable, ICommandService } from '@univerjs/core';
|
|
17
|
-
import { TextSelectionManagerService } from '../services/text-selection-manager.service';
|
|
18
|
-
/**
|
|
19
|
-
* Used to manage the addition and removal of inline styles,
|
|
20
|
-
* and to assemble the command parameters here,
|
|
21
|
-
* some of the logic may be moved to the command, as the command is testable.
|
|
22
|
-
*/
|
|
23
|
-
export declare class InlineFormatController extends Disposable {
|
|
24
|
-
private readonly _textSelectionManagerService;
|
|
25
|
-
private readonly _commandService;
|
|
26
|
-
constructor(_textSelectionManagerService: TextSelectionManagerService, _commandService: ICommandService);
|
|
27
|
-
private _commandExecutedListener;
|
|
28
|
-
private _handleInlineFormat;
|
|
29
|
-
}
|