@univerjs/docs 0.4.2 → 0.5.0-beta.0

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 CHANGED
@@ -1 +1 @@
1
- "use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),engineRender=require("@univerjs/engine-render"),rxjs=require("rxjs"),SetTextSelectionsOperation={id:"doc.operation.set-selections",type:core.CommandType.OPERATION,handler:__name(()=>!0,"handler")};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4"),_a;exports.DocSelectionManagerService=(_a=class extends core.RxDisposable{constructor(_commandService,_univerInstanceService){super();__publicField(this,"_currentSelection",null);__publicField(this,"_textSelectionInfo",new Map);__publicField(this,"_textSelection$",new rxjs.Subject);__publicField(this,"textSelection$",this._textSelection$.asObservable());__publicField(this,"_refreshSelection$",new rxjs.BehaviorSubject(null));__publicField(this,"refreshSelection$",this._refreshSelection$.asObservable());this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_DOC).pipe(rxjs.takeUntil(this.dispose$)).subscribe(documentModel=>{if(documentModel==null)return;const unitId=documentModel.getUnitId();this._setCurrentSelectionNotRefresh({unitId,subUnitId:unitId})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(params=this._currentSelection){return this._getTextRanges(params)}refreshSelection(params=this._currentSelection){params!=null&&this._refresh(params)}__TEST_ONLY_setCurrentSelection(param){this._currentSelection=param,this._refresh(param)}getTextRanges(params=this._currentSelection){var _a6;return(_a6=this._getTextRanges(params))==null?void 0:_a6.textRanges}getRectRanges(params=this._currentSelection){var _a6;return(_a6=this._getTextRanges(params))==null?void 0:_a6.rectRanges}getDocRanges(params=this._currentSelection){var _a6,_b;const textRanges=(_a6=this.getTextRanges(params))!=null?_a6:[],rectRanges=(_b=this.getRectRanges(params))!=null?_b:[];return[...textRanges,...rectRanges].filter(range=>range.startOffset!=null&&range.endOffset!=null).sort((a,b)=>a.startOffset>b.startOffset?1:a.startOffset<b.startOffset?-1:0)}getActiveTextRange(){const selectionInfo=this._getTextRanges(this._currentSelection);if(selectionInfo==null)return;const{textRanges}=selectionInfo;return textRanges.find(textRange=>textRange.isActive)}getActiveRectRange(){const selectionInfo=this._getTextRanges(this._currentSelection);if(selectionInfo==null)return;const{rectRanges}=selectionInfo;return rectRanges.find(rectRange=>rectRange.isActive)}__TEST_ONLY_add(textRanges,isEditing=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges,rectRanges:[],segmentId:"",segmentPage:-1,isEditing,style:engineRender.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(docRanges,isEditing=!0,options){return this.replaceDocRanges(docRanges,this._currentSelection,isEditing,options)}replaceDocRanges(docRanges,params=this._currentSelection,isEditing=!0,options){if(params==null)return;const{unitId,subUnitId}=params;this._refreshSelection$.next({unitId,subUnitId,docRanges,isEditing,options})}__replaceTextRangesWithNoRefresh(textSelectionInfo){if(this._currentSelection==null)return;const params={...this._currentSelection,...textSelectionInfo};this._replaceByParam(params),this._textSelection$.next(params);const{unitId,subUnitId,segmentId,style,textRanges,rectRanges,isEditing}=params,ranges=[...textRanges,...rectRanges].filter(range=>range.startOffset!=null&&range.endOffset!=null).sort((a,b)=>a.startOffset>b.startOffset?1:a.startOffset<b.startOffset?-1:0);this._commandService.executeCommand(SetTextSelectionsOperation.id,{unitId,subUnitId,segmentId,style,isEditing,ranges})}dispose(){this._textSelection$.complete()}_setCurrentSelectionNotRefresh(param){this._currentSelection=param}_getTextRanges(param){var _a6;if(param==null)return;const{unitId,subUnitId=""}=param;return(_a6=this._textSelectionInfo.get(unitId))==null?void 0:_a6.get(subUnitId)}_refresh(param){const allTextSelectionInfo=this._getTextRanges(param);if(allTextSelectionInfo==null)return;const{textRanges,rectRanges}=allTextSelectionInfo,docRanges=[...textRanges,...rectRanges],{unitId,subUnitId}=param;this._refreshSelection$.next({unitId,subUnitId,docRanges,isEditing:!1})}_replaceByParam(insertParam){const{unitId,subUnitId,...selectionInsertParam}=insertParam;this._textSelectionInfo.has(unitId)||this._textSelectionInfo.set(unitId,new Map),this._textSelectionInfo.get(unitId).set(subUnitId,{...selectionInsertParam})}_addByParam(insertParam){const{unitId,subUnitId,...selectionInsertParam}=insertParam;this._textSelectionInfo.has(unitId)||this._textSelectionInfo.set(unitId,new Map);const unitTextRange=this._textSelectionInfo.get(unitId);unitTextRange.has(subUnitId)?unitTextRange.get(subUnitId).textRanges.push(...insertParam.textRanges):unitTextRange.set(subUnitId,{...selectionInsertParam})}},__name(_a,"DocSelectionManagerService"),_a);exports.DocSelectionManagerService=__decorateClass$4([__decorateParam$4(0,core.ICommandService),__decorateParam$4(1,core.IUniverInstanceService)],exports.DocSelectionManagerService);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a2;exports.DocSkeletonManagerService=(_a2=class extends core.RxDisposable{constructor(_context,_localeService,_univerInstanceService){super();__publicField(this,"_skeleton");__publicField(this,"_docViewModel");__publicField(this,"_currentSkeleton$",new rxjs.BehaviorSubject(null));__publicField(this,"currentSkeleton$",this._currentSkeleton$.asObservable());__publicField(this,"_currentSkeletonBefore$",new rxjs.BehaviorSubject(null));__publicField(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());__publicField(this,"_currentViewModel$",new rxjs.BehaviorSubject(null));__publicField(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=_context,this._localeService=_localeService,this._univerInstanceService=_univerInstanceService,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_DOC).pipe(rxjs.takeUntil(this.dispose$)).subscribe(documentModel=>{documentModel&&documentModel.getUnitId()===this._context.unitId&&this._update(documentModel)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const documentDataModel=this._context.unit;this._update(documentDataModel)}_update(documentDataModel){const unitId=this._context.unitId;if(documentDataModel.getBody()==null)return;this._docViewModel&&core.isInternalEditorID(unitId)?(this._docViewModel.reset(documentDataModel),this._context.unit=documentDataModel):this._docViewModel||(this._docViewModel=this._buildDocViewModel(documentDataModel)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));const skeleton=this._skeleton;skeleton.calculate(),this._currentSkeletonBefore$.next(skeleton),this._currentSkeleton$.next(skeleton),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(documentViewModel){return engineRender.DocumentSkeleton.create(documentViewModel,this._localeService)}_buildDocViewModel(documentDataModel){return new engineRender.DocumentViewModel(documentDataModel)}},__name(_a2,"DocSkeletonManagerService"),_a2);exports.DocSkeletonManagerService=__decorateClass$3([__decorateParam$3(1,core.Inject(core.LocaleService)),__decorateParam$3(2,core.IUniverInstanceService)],exports.DocSkeletonManagerService);const _DocStateEmitService=class _DocStateEmitService extends core.RxDisposable{constructor(){super();__publicField(this,"_docStateChangeParams$",new rxjs.BehaviorSubject(null));__publicField(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(params){this._docStateChangeParams$.next(params)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}};__name(_DocStateEmitService,"DocStateEmitService");let DocStateEmitService=_DocStateEmitService;const RichTextEditingMutationId="doc.mutation.rich-text-editing",RichTextEditingMutation={id:RichTextEditingMutationId,type:core.CommandType.MUTATION,handler:__name((accessor,params)=>{var _a6,_b;const{unitId,segmentId="",actions,textRanges,prevTextRanges,trigger,noHistory,isCompositionEnd,noNeedSetTextRange,debounce,isEditing=!0,isSync,syncer}=params,univerInstanceService=accessor.get(core.IUniverInstanceService),renderManagerService=accessor.get(engineRender.IRenderManagerService),docStateEmitService=accessor.get(DocStateEmitService),documentDataModel=univerInstanceService.getUniverDocInstance(unitId),documentViewModel=(_a6=renderManagerService.getRenderById(unitId))==null?void 0:_a6.with(exports.DocSkeletonManagerService).getViewModel();if(documentDataModel==null||documentViewModel==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);const docSelectionManagerService=accessor.get(exports.DocSelectionManagerService),docRanges=(_b=docSelectionManagerService.getDocRanges())!=null?_b:[],disabled=!!documentDataModel.getSnapshot().disabled;if(core.JSONX.isNoop(actions)||actions&&actions.length===0||disabled)return{unitId,actions:[],textRanges:docRanges};const undoActions=core.JSONX.invertWithDoc(actions,documentDataModel.getSnapshot());documentDataModel.apply(actions),documentViewModel.reset(documentDataModel),!noNeedSetTextRange&&textRanges&&trigger!=null&&queueMicrotask(()=>{docSelectionManagerService.replaceDocRanges(textRanges,{unitId,subUnitId:unitId},isEditing,params.options)});const changeState={commandId:RichTextEditingMutationId,unitId,segmentId,trigger,noHistory,debounce,redoState:{actions,textRanges},undoState:{actions:undoActions,textRanges:prevTextRanges!=null?prevTextRanges:docRanges},isCompositionEnd,isSync,syncer};return docStateEmitService.emitStateChangeInfo(changeState),{unitId,actions:undoActions,textRanges:docRanges}},"handler")},DocsRenameMutation={id:"doc.mutation.rename-doc",type:core.CommandType.MUTATION,handler:__name((accessor,params)=>{const doc=accessor.get(core.IUniverInstanceService).getUnit(params.unitId,core.UniverInstanceType.UNIVER_DOC);return doc?(doc.setName(params.name),!0):!1},"handler")},PLUGIN_CONFIG_KEY="docs.config",defaultPluginConfig={};var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a3;let DocCustomRangeController=(_a3=class extends core.Disposable{constructor(_commandService,_textSelectionManagerService,_univerInstanceService){super(),this._commandService=_commandService,this._textSelectionManagerService=_textSelectionManagerService,this._univerInstanceService=_univerInstanceService,this._initSelectionChange()}_transformCustomRange(doc,selection){var _a6;const{startOffset,endOffset,collapsed}=selection,customRanges=(_a6=doc.getCustomRanges())==null?void 0:_a6.filter(range=>!range.wholeEntity||startOffset<=range.startIndex&&endOffset>range.endIndex?!1:collapsed?range.startIndex<startOffset&&range.endIndex>=endOffset:core.BuildTextUtils.range.isIntersects(startOffset,endOffset-1,range.startIndex,range.endIndex));if(customRanges!=null&&customRanges.length){let start=startOffset,end=endOffset;return customRanges.forEach(range=>{start=Math.min(range.startIndex,start),end=Math.max(range.endIndex+1,end)}),{...selection,startOffset:start,endOffset:end,collapsed:start===end}}return selection}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===SetTextSelectionsOperation.id){const params=commandInfo.params,{unitId,ranges,isEditing}=params,doc=this._univerInstanceService.getUnit(unitId);if(!doc)return;const transformedRanges=ranges.map(range=>this._transformCustomRange(doc,range));transformedRanges.some((range,i)=>ranges[i]!==range)&&this._textSelectionManagerService.replaceTextRanges(transformedRanges,isEditing)}}))}},__name(_a3,"DocCustomRangeController"),_a3);DocCustomRangeController=__decorateClass$2([__decorateParam$2(0,core.ICommandService),__decorateParam$2(1,core.Inject(exports.DocSelectionManagerService)),__decorateParam$2(2,core.IUniverInstanceService)],DocCustomRangeController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");const PLUGIN_NAME="DOCS_PLUGIN";var _a4;exports.UniverDocsPlugin=(_a4=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[RichTextEditingMutation,DocsRenameMutation,SetTextSelectionsOperation].forEach(command=>{this._injector.get(core.ICommandService).registerCommand(command)})}_initializeDependencies(){[[exports.DocSelectionManagerService],[DocStateEmitService],[DocCustomRangeController]].forEach(d=>this._injector.add(d))}onReady(){this._injector.get(DocCustomRangeController)}},__name(_a4,"UniverDocsPlugin"),__publicField(_a4,"pluginName",PLUGIN_NAME),_a4);exports.UniverDocsPlugin=__decorateClass$1([__decorateParam$1(1,core.Inject(core.Injector)),__decorateParam$1(2,core.IConfigService)],exports.UniverDocsPlugin);const CUSTOM_RANGE=core.createInterceptorKey("CUSTOM_RANGE"),CUSTOM_DECORATION=core.createInterceptorKey("CUSTOM_DECORATION"),DOC_INTERCEPTOR_POINT={CUSTOM_RANGE,CUSTOM_DECORATION};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),_a5;exports.DocInterceptorService=(_a5=class extends core.Disposable{constructor(_context,_docSkeletonManagerService){super();__publicField(this,"_interceptorsByName",new Map);this._context=_context,this._docSkeletonManagerService=_docSkeletonManagerService;const viewModel=this._docSkeletonManagerService.getViewModel(),unitId=viewModel.getDataModel().getUnitId();if(unitId===core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||unitId===core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(viewModel)),this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{priority:-1,handler:__name((data,pos,next)=>next(data),"handler")}));let disposableCollection=new core.DisposableCollection;viewModel.segmentViewModels$.subscribe(segmentViewModels=>{disposableCollection.dispose(),disposableCollection=new core.DisposableCollection,segmentViewModels.forEach(segmentViewModel=>{disposableCollection.add(this.interceptDocumentViewModel(segmentViewModel))})}),this.disposeWithMe(disposableCollection)}intercept(name,interceptor){const key=name;this._interceptorsByName.has(key)||this._interceptorsByName.set(key,[]);const interceptors=this._interceptorsByName.get(key);return interceptors.push(interceptor),this._interceptorsByName.set(key,interceptors.sort((a,b)=>{var _a6,_b;return((_a6=b.priority)!=null?_a6:0)-((_b=a.priority)!=null?_b:0)})),this.disposeWithMe(core.toDisposable(()=>core.remove(this._interceptorsByName.get(key),interceptor)))}fetchThroughInterceptors(name){const key=name,interceptors=this._interceptorsByName.get(key);return core.composeInterceptors(interceptors||[])}interceptDocumentViewModel(viewModel){const disposableCollection=new core.DisposableCollection;return disposableCollection.add(viewModel.registerCustomRangeInterceptor({getCustomRange:__name(index=>{var _a6;return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(viewModel.getCustomRangeRaw(index),{index,unitId:viewModel.getDataModel().getUnitId(),customRanges:(_a6=viewModel.getDataModel().getCustomRanges())!=null?_a6:[]})},"getCustomRange"),getCustomDecoration:__name(index=>{var _a6;return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(viewModel.getCustomDecorationRaw(index),{index,unitId:viewModel.getDataModel().getUnitId(),customDecorations:(_a6=viewModel.getDataModel().getCustomDecorations())!=null?_a6:[]})},"getCustomDecoration")})),disposableCollection}},__name(_a5,"DocInterceptorService"),_a5);exports.DocInterceptorService=__decorateClass([__decorateParam(1,core.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);exports.DOC_INTERCEPTOR_POINT=DOC_INTERCEPTOR_POINT;exports.DocStateEmitService=DocStateEmitService;exports.RichTextEditingMutation=RichTextEditingMutation;exports.SetTextSelectionsOperation=SetTextSelectionsOperation;
1
+ "use strict";var z=Object.defineProperty;var G=(o,i,e)=>i in o?z(o,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[i]=e;var d=(o,i,e)=>G(o,typeof i!="symbol"?i+"":i,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),C=require("@univerjs/engine-render"),p=require("rxjs"),b={id:"doc.operation.set-selections",type:c.CommandType.OPERATION,handler:()=>!0};var k=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(o,i,e,t)=>{for(var n=t>1?void 0:t?W(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&&k(i,e,n),n},j=(o,i)=>(e,t)=>i(e,t,o);exports.DocSelectionManagerService=class extends c.RxDisposable{constructor(e,t){super();d(this,"_currentSelection",null);d(this,"_textSelectionInfo",new Map);d(this,"_textSelection$",new p.Subject);d(this,"textSelection$",this._textSelection$.asObservable());d(this,"_refreshSelection$",new p.BehaviorSubject(null));d(this,"refreshSelection$",this._refreshSelection$.asObservable());this._commandService=e,this._univerInstanceService=t,this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_DOC).pipe(p.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=e.getUnitId();this._setCurrentSelectionNotRefresh({unitId:t,subUnitId:t})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(e=this._currentSelection){return this._getTextRanges(e)}refreshSelection(e=this._currentSelection){e!=null&&this._refresh(e)}__TEST_ONLY_setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}getTextRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.textRanges}getRectRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.rectRanges}getDocRanges(e=this._currentSelection){var r,a;const t=(r=this.getTextRanges(e))!=null?r:[],n=(a=this.getRectRanges(e))!=null?a:[];return[...t,...n].filter(l=>l.startOffset!=null&&l.endOffset!=null).sort((l,u)=>l.startOffset>u.startOffset?1:l.startOffset<u.startOffset?-1:0)}getActiveTextRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t}=e;return t.find(n=>n.isActive)}getActiveRectRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{rectRanges:t}=e;return t.find(n=>n.isActive)}__TEST_ONLY_add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:"",segmentPage:-1,isEditing:t,style:C.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,s){if(t==null)return;const{unitId:r,subUnitId:a}=t;this._refreshSelection$.next({unitId:r,subUnitId:a,docRanges:e,isEditing:n,options:s})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;const n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:s,subUnitId:r,segmentId:a,style:l,textRanges:u,rectRanges:g,isEditing:h}=n,S=[...u,...g].filter(_=>_.startOffset!=null&&_.endOffset!=null).sort((_,f)=>_.startOffset>f.startOffset?1:_.startOffset<f.startOffset?-1:0);this._commandService.executeCommand(b.id,{unitId:s,subUnitId:r,segmentId:a,style:l,isEditing:h,ranges:S})}dispose(){this._textSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_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);if(t==null)return;const{textRanges:n,rectRanges:s}=t,r=[...n,...s],{unitId:a,subUnitId:l}=e;this._refreshSelection$.next({unitId:a,subUnitId:l,docRanges:r,isEditing:!1})}_replaceByParam(e){const{unitId:t,subUnitId:n,...s}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...s})}_addByParam(e){const{unitId:t,subUnitId:n,...s}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const r=this._textSelectionInfo.get(t);r.has(n)?r.get(n).textRanges.push(...e.textRanges):r.set(n,{...s})}};exports.DocSelectionManagerService=J([j(0,c.ICommandService),j(1,c.IUniverInstanceService)],exports.DocSelectionManagerService);var Y=Object.defineProperty,K=Object.getOwnPropertyDescriptor,q=(o,i,e,t)=>{for(var n=t>1?void 0:t?K(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&&Y(i,e,n),n},V=(o,i)=>(e,t)=>i(e,t,o);exports.DocSkeletonManagerService=class extends c.RxDisposable{constructor(e,t,n){super();d(this,"_skeleton");d(this,"_docViewModel");d(this,"_currentSkeleton$",new p.BehaviorSubject(null));d(this,"currentSkeleton$",this._currentSkeleton$.asObservable());d(this,"_currentSkeletonBefore$",new p.BehaviorSubject(null));d(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());d(this,"_currentViewModel$",new p.BehaviorSubject(null));d(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=e,this._localeService=t,this._univerInstanceService=n,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_DOC).pipe(p.takeUntil(this.dispose$)).subscribe(s=>{s&&s.getUnitId()===this._context.unitId&&this._update(s)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const e=this._context.unit;this._update(e)}_update(e){const t=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&c.isInternalEditorID(t)?(this._docViewModel.reset(e),this._context.unit=e):this._docViewModel||(this._docViewModel=this._buildDocViewModel(e)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));const n=this._skeleton;n.calculate(),this._currentSkeletonBefore$.next(n),this._currentSkeleton$.next(n),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return C.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new C.DocumentViewModel(e)}};exports.DocSkeletonManagerService=q([V(1,c.Inject(c.LocaleService)),V(2,c.IUniverInstanceService)],exports.DocSkeletonManagerService);class P extends c.RxDisposable{constructor(){super();d(this,"_docStateChangeParams$",new p.BehaviorSubject(null));d(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const A="doc.mutation.rich-text-editing",O={id:A,type:c.CommandType.MUTATION,handler:(o,i)=>{var $,B;const{unitId:e,segmentId:t="",actions:n,textRanges:s,prevTextRanges:r,trigger:a,noHistory:l,isCompositionEnd:u,noNeedSetTextRange:g,debounce:h,isEditing:S=!0,isSync:_,syncer:f}=i,m=o.get(c.IUniverInstanceService),I=o.get(C.IRenderManagerService),R=o.get(P),v=m.getUniverDocInstance(e),D=($=I.getRenderById(e))==null?void 0:$.with(exports.DocSkeletonManagerService).getViewModel();if(v==null||D==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const x=o.get(exports.DocSelectionManagerService),U=(B=x.getDocRanges())!=null?B:[],F=!!v.getSnapshot().disabled;if(c.JSONX.isNoop(n)||n&&n.length===0||F)return{unitId:e,actions:[],textRanges:U};const N=c.JSONX.invertWithDoc(n,v.getSnapshot());v.apply(n),D.reset(v),!g&&s&&a!=null&&queueMicrotask(()=>{x.replaceDocRanges(s,{unitId:e,subUnitId:e},S,i.options)});const L={commandId:A,unitId:e,segmentId:t,trigger:a,noHistory:l,debounce:h,redoState:{actions:n,textRanges:s},undoState:{actions:N,textRanges:r!=null?r:U},isCompositionEnd:u,isSync:_,syncer:f};return R.emitStateChangeInfo(L),{unitId:e,actions:N,textRanges:U}}},H={id:"doc.mutation.rename-doc",type:c.CommandType.MUTATION,handler:(o,i)=>{const t=o.get(c.IUniverInstanceService).getUnit(i.unitId,c.UniverInstanceType.UNIVER_DOC);return t?(t.setName(i.name),!0):!1}},Q="docs.config",Z={};var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(o,i,e,t)=>{for(var n=t>1?void 0:t?te(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&&ee(i,e,n),n},y=(o,i)=>(e,t)=>i(e,t,o);let T=class extends c.Disposable{constructor(o,i,e){super(),this._commandService=o,this._textSelectionManagerService=i,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(o,i){var r;const{startOffset:e,endOffset:t,collapsed:n}=i,s=(r=o.getCustomRanges())==null?void 0:r.filter(a=>!a.wholeEntity||e<=a.startIndex&&t>a.endIndex?!1:n?a.startIndex<e&&a.endIndex>=t:c.BuildTextUtils.range.isIntersects(e,t-1,a.startIndex,a.endIndex));if(s!=null&&s.length){let a=e,l=t;return s.forEach(u=>{a=Math.min(u.startIndex,a),l=Math.max(u.endIndex+1,l)}),{...i,startOffset:a,endOffset:l,collapsed:a===l}}return i}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===b.id){const i=o.params,{unitId:e,ranges:t,isEditing:n}=i,s=this._univerInstanceService.getUnit(e);if(!s)return;const r=t.map(a=>this._transformCustomRange(s,a));r.some((a,l)=>t[l]!==a)&&this._textSelectionManagerService.replaceTextRanges(r,n)}}))}};T=ne([y(0,c.ICommandService),y(1,c.Inject(exports.DocSelectionManagerService)),y(2,c.IUniverInstanceService)],T);var ie=Object.defineProperty,se=Object.getOwnPropertyDescriptor,re=(o,i,e,t)=>{for(var n=t>1?void 0:t?se(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&&ie(i,e,n),n},X=(o,i)=>(e,t)=>i(e,t,o);const oe="DOCS_PLUGIN";var w;exports.UniverDocsPlugin=(w=class extends c.Plugin{constructor(i=Z,e,t){super(),this._config=i,this._injector=e,this._configService=t;const{...n}=this._config;this._configService.setConfig(Q,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[O,H,b].forEach(i=>{this._injector.get(c.ICommandService).registerCommand(i)})}_initializeDependencies(){[[exports.DocSelectionManagerService],[P],[T]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(T)}},d(w,"pluginName",oe),w);exports.UniverDocsPlugin=re([X(1,c.Inject(c.Injector)),X(2,c.IConfigService)],exports.UniverDocsPlugin);const ce=c.createInterceptorKey("CUSTOM_RANGE"),ae=c.createInterceptorKey("CUSTOM_DECORATION"),M={CUSTOM_RANGE:ce,CUSTOM_DECORATION:ae};var le=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,de=(o,i,e,t)=>{for(var n=t>1?void 0:t?ue(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&&le(i,e,n),n},ge=(o,i)=>(e,t)=>i(e,t,o);exports.DocInterceptorService=class extends c.Disposable{constructor(e,t){super();d(this,"_interceptorsByName",new Map);this._context=e,this._docSkeletonManagerService=t;const n=this._docSkeletonManagerService.getViewModel(),s=n.getDataModel().getUnitId();if(s===c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||s===c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(n)),this.disposeWithMe(this.intercept(M.CUSTOM_RANGE,{priority:-1,handler:(a,l,u)=>u(a)}));let r=new c.DisposableCollection;n.segmentViewModels$.subscribe(a=>{r.dispose(),r=new c.DisposableCollection,a.forEach(l=>{r.add(this.interceptDocumentViewModel(l))})}),this.disposeWithMe(r)}intercept(e,t){const n=e;this._interceptorsByName.has(n)||this._interceptorsByName.set(n,[]);const s=this._interceptorsByName.get(n);return s.push(t),this._interceptorsByName.set(n,s.sort((r,a)=>{var l,u;return((l=a.priority)!=null?l:0)-((u=r.priority)!=null?u:0)})),this.disposeWithMe(c.toDisposable(()=>c.remove(this._interceptorsByName.get(n),t)))}fetchThroughInterceptors(e){const t=e,n=this._interceptorsByName.get(t);return c.composeInterceptors(n||[])}interceptDocumentViewModel(e){const t=new c.DisposableCollection;return t.add(e.registerCustomRangeInterceptor({getCustomRange:n=>{var s;return this.fetchThroughInterceptors(M.CUSTOM_RANGE)(e.getCustomRangeRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customRanges:(s=e.getDataModel().getCustomRanges())!=null?s:[]})},getCustomDecoration:n=>{var s;return this.fetchThroughInterceptors(M.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(s=e.getDataModel().getCustomDecorations())!=null?s:[]})}})),t}};exports.DocInterceptorService=de([ge(1,c.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);function E(o,i=""){if(!i)return["body"];const{headers:e,footers:t}=o.getSnapshot();if(e==null&&t==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[i])!=null)return["headers",i,"body"];if((t==null?void 0:t[i])!=null)return["footers",i,"body"];throw new Error("Segment id not found in headers or footers")}function _e(o,i,e){const{unitId:t,segmentId:n}=i,r=o.get(c.IUniverInstanceService).getUnit(t);if(!r)return!1;const a={id:O.id,params:{unitId:i.unitId,actions:[],textRanges:void 0}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.add({...i,body:e});if(!u)return!1;const g=E(r,n);return a.params.actions=l.editOp(u.serialize(),g),a}function he(o,i){var x;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:r,selection:a}=i,l=o.get(exports.DocSelectionManagerService),u=o.get(c.IUniverInstanceService),g=a!=null?a:(x=l.getTextRanges({unitId:r,subUnitId:r}))==null?void 0:x[0],h=g==null?void 0:g.segmentId;if(!g)return!1;const S=u.getUnit(r,c.UniverInstanceType.UNIVER_DOC);if(!S)return!1;const _=S.getSelfOrHeaderFooterModel(g.segmentId).getBody();if(!_)return!1;const{startOffset:f,endOffset:m}=c.BuildTextUtils.selection.normalizeSelection(g),I=c.BuildTextUtils.customRange.add({range:{startOffset:f,endOffset:m,collapsed:f===m},rangeId:e,rangeType:t,segmentId:h,wholeEntity:n,properties:s,body:_});if(!I)return!1;const R=c.JSONX.getInstance(),v={id:O.id,params:{unitId:r,actions:[],textRanges:I.selections},textX:I},D=E(S,h);return v.params.actions=R.editOp(I.serialize(),D),v}function Se(o,i){const{unitId:e,segmentId:t,insert:n}=i,r=o.get(c.IUniverInstanceService).getUnit(e);if(!r)return!1;const a={id:O.id,params:{unitId:i.unitId,actions:[],textRanges:void 0,segmentId:t}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.delete(o,{documentDataModel:r,rangeId:i.rangeId,insert:n,segmentId:t});if(!u)return!1;const g=E(r,t);return a.params.actions=l.editOp(u.serialize(),g),a.params.textRanges=u.selections,a}function fe(o,i){var f,m,I,R;const{unitId:e,body:t,doc:n}=i;let s=n;if(s||(s=o.get(c.IUniverInstanceService).getUnit(e)),!s)return!1;const r=(f=i.selection)==null?void 0:f.segmentId,a=(m=s.getSelfOrHeaderFooterModel(r))==null?void 0:m.getBody();if(!a)return!1;const l=o.get(exports.DocSelectionManagerService),u=(I=i.selection)!=null?I:l.getActiveTextRange();if(!u||!a)return!1;const g=(R=i.textRanges)!=null?R:[{startOffset:u.startOffset+t.dataStream.length,endOffset:u.startOffset+t.dataStream.length,collapsed:!0,segmentId:r}],h=c.BuildTextUtils.selection.replace({selection:u,body:t,doc:s});if(!h)return!1;const S={id:O.id,params:{unitId:e,actions:[],textRanges:g,debounce:!0,segmentId:r},textX:h},_=c.JSONX.getInstance();return S.params.actions=_.editOp(h.serialize()),S}exports.DOC_INTERCEPTOR_POINT=M;exports.DocStateEmitService=P;exports.RichTextEditingMutation=O;exports.SetTextSelectionsOperation=b;exports.addCustomRangeBySelectionFactory=he;exports.addCustomRangeFactory=_e;exports.deleteCustomRangeFactory=Se;exports.replaceSelectionFactory=fe;
package/lib/es/index.js CHANGED
@@ -1,96 +1,95 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { CommandType, RxDisposable, UniverInstanceType, ICommandService, IUniverInstanceService, Inject, LocaleService, isInternalEditorID, JSONX, Disposable, BuildTextUtils, Injector, Plugin, IConfigService, createInterceptorKey, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DisposableCollection, toDisposable, remove, composeInterceptors } from "@univerjs/core";
6
- import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE, DocumentSkeleton, DocumentViewModel, IRenderManagerService } from "@univerjs/engine-render";
7
- import { Subject, BehaviorSubject, takeUntil } from "rxjs";
8
- const SetTextSelectionsOperation = {
1
+ var se = Object.defineProperty;
2
+ var ie = (i, e, t) => e in i ? se(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var u = (i, e, t) => ie(i, typeof e != "symbol" ? e + "" : e, t);
4
+ import { CommandType as B, RxDisposable as j, UniverInstanceType as y, ICommandService as A, IUniverInstanceService as p, Inject as $, LocaleService as re, isInternalEditorID as oe, JSONX as O, Disposable as J, BuildTextUtils as x, Injector as ce, Plugin as ae, IConfigService as le, createInterceptorKey as Q, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as ue, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as de, DisposableCollection as E, toDisposable as ge, remove as _e, composeInterceptors as fe } from "@univerjs/core";
5
+ import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as he, DocumentSkeleton as Se, DocumentViewModel as pe, IRenderManagerService as Ie } from "@univerjs/engine-render";
6
+ import { Subject as me, BehaviorSubject as M, takeUntil as Z } from "rxjs";
7
+ const L = {
9
8
  id: "doc.operation.set-selections",
10
- type: CommandType.OPERATION,
11
- handler: /* @__PURE__ */ __name(() => !0, "handler")
9
+ type: B.OPERATION,
10
+ handler: () => !0
12
11
  };
13
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
14
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
15
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
16
- return kind && result && __defProp$4(target, key, result), result;
17
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a;
18
- let DocSelectionManagerService = (_a = class extends RxDisposable {
19
- constructor(_commandService, _univerInstanceService) {
12
+ var ve = Object.defineProperty, Re = Object.getOwnPropertyDescriptor, Oe = (i, e, t, n) => {
13
+ for (var s = n > 1 ? void 0 : n ? Re(e, t) : e, r = i.length - 1, o; r >= 0; r--)
14
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
15
+ return n && s && ve(e, t, s), s;
16
+ }, W = (i, e) => (t, n) => e(t, n, i);
17
+ let v = class extends j {
18
+ constructor(e, t) {
20
19
  super();
21
- __publicField(this, "_currentSelection", null);
22
- __publicField(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
23
- __publicField(this, "_textSelection$", new Subject());
24
- __publicField(this, "textSelection$", this._textSelection$.asObservable());
25
- __publicField(this, "_refreshSelection$", new BehaviorSubject(null));
26
- __publicField(this, "refreshSelection$", this._refreshSelection$.asObservable());
27
- this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._listenCurrentUnit();
20
+ u(this, "_currentSelection", null);
21
+ u(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
22
+ u(this, "_textSelection$", new me());
23
+ u(this, "textSelection$", this._textSelection$.asObservable());
24
+ u(this, "_refreshSelection$", new M(null));
25
+ u(this, "refreshSelection$", this._refreshSelection$.asObservable());
26
+ this._commandService = e, this._univerInstanceService = t, this._listenCurrentUnit();
28
27
  }
29
28
  _listenCurrentUnit() {
30
- this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
31
- if (documentModel == null)
29
+ this._univerInstanceService.getCurrentTypeOfUnit$(y.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((e) => {
30
+ if (e == null)
32
31
  return;
33
- const unitId = documentModel.getUnitId();
32
+ const t = e.getUnitId();
34
33
  this._setCurrentSelectionNotRefresh({
35
- unitId,
36
- subUnitId: unitId
34
+ unitId: t,
35
+ subUnitId: t
37
36
  });
38
37
  });
39
38
  }
40
39
  __getCurrentSelection() {
41
40
  return this._currentSelection;
42
41
  }
43
- getSelectionInfo(params = this._currentSelection) {
44
- return this._getTextRanges(params);
42
+ getSelectionInfo(e = this._currentSelection) {
43
+ return this._getTextRanges(e);
45
44
  }
46
- refreshSelection(params = this._currentSelection) {
47
- params != null && this._refresh(params);
45
+ refreshSelection(e = this._currentSelection) {
46
+ e != null && this._refresh(e);
48
47
  }
49
48
  // **Only used in test case** because this does not go through the render layer.
50
- __TEST_ONLY_setCurrentSelection(param) {
51
- this._currentSelection = param, this._refresh(param);
49
+ __TEST_ONLY_setCurrentSelection(e) {
50
+ this._currentSelection = e, this._refresh(e);
52
51
  }
53
- getTextRanges(params = this._currentSelection) {
54
- var _a6;
55
- return (_a6 = this._getTextRanges(params)) == null ? void 0 : _a6.textRanges;
52
+ getTextRanges(e = this._currentSelection) {
53
+ var t;
54
+ return (t = this._getTextRanges(e)) == null ? void 0 : t.textRanges;
56
55
  }
57
- getRectRanges(params = this._currentSelection) {
58
- var _a6;
59
- return (_a6 = this._getTextRanges(params)) == null ? void 0 : _a6.rectRanges;
56
+ getRectRanges(e = this._currentSelection) {
57
+ var t;
58
+ return (t = this._getTextRanges(e)) == null ? void 0 : t.rectRanges;
60
59
  }
61
- getDocRanges(params = this._currentSelection) {
62
- var _a6, _b;
63
- const textRanges = (_a6 = this.getTextRanges(params)) != null ? _a6 : [], rectRanges = (_b = this.getRectRanges(params)) != null ? _b : [];
64
- return [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0);
60
+ getDocRanges(e = this._currentSelection) {
61
+ var r, o;
62
+ const t = (r = this.getTextRanges(e)) != null ? r : [], n = (o = this.getRectRanges(e)) != null ? o : [];
63
+ return [...t, ...n].filter((c) => c.startOffset != null && c.endOffset != null).sort((c, a) => c.startOffset > a.startOffset ? 1 : c.startOffset < a.startOffset ? -1 : 0);
65
64
  }
66
65
  getActiveTextRange() {
67
- const selectionInfo = this._getTextRanges(this._currentSelection);
68
- if (selectionInfo == null)
66
+ const e = this._getTextRanges(this._currentSelection);
67
+ if (e == null)
69
68
  return;
70
- const { textRanges } = selectionInfo;
71
- return textRanges.find((textRange) => textRange.isActive);
69
+ const { textRanges: t } = e;
70
+ return t.find((n) => n.isActive);
72
71
  }
73
72
  /**
74
73
  *
75
74
  * @deprecated
76
75
  */
77
76
  getActiveRectRange() {
78
- const selectionInfo = this._getTextRanges(this._currentSelection);
79
- if (selectionInfo == null)
77
+ const e = this._getTextRanges(this._currentSelection);
78
+ if (e == null)
80
79
  return;
81
- const { rectRanges } = selectionInfo;
82
- return rectRanges.find((rectRange) => rectRange.isActive);
80
+ const { rectRanges: t } = e;
81
+ return t.find((n) => n.isActive);
83
82
  }
84
83
  // **Only used in test case** because this does not go through the render layer.
85
- __TEST_ONLY_add(textRanges, isEditing = !0) {
84
+ __TEST_ONLY_add(e, t = !0) {
86
85
  this._currentSelection != null && this._addByParam({
87
86
  ...this._currentSelection,
88
- textRanges,
87
+ textRanges: e,
89
88
  rectRanges: [],
90
89
  segmentId: "",
91
90
  segmentPage: -1,
92
- isEditing,
93
- style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE
91
+ isEditing: t,
92
+ style: he
94
93
  // mock style.
95
94
  });
96
95
  }
@@ -98,104 +97,104 @@ let DocSelectionManagerService = (_a = class extends RxDisposable {
98
97
  /**
99
98
  * @deprecated pls use replaceDocRanges.
100
99
  */
101
- replaceTextRanges(docRanges, isEditing = !0, options) {
100
+ replaceTextRanges(e, t = !0, n) {
102
101
  return this.replaceDocRanges(
103
- docRanges,
102
+ e,
104
103
  this._currentSelection,
105
- isEditing,
106
- options
104
+ t,
105
+ n
107
106
  );
108
107
  }
109
- replaceDocRanges(docRanges, params = this._currentSelection, isEditing = !0, options) {
110
- if (params == null)
108
+ replaceDocRanges(e, t = this._currentSelection, n = !0, s) {
109
+ if (t == null)
111
110
  return;
112
- const { unitId, subUnitId } = params;
111
+ const { unitId: r, subUnitId: o } = t;
113
112
  this._refreshSelection$.next({
114
- unitId,
115
- subUnitId,
116
- docRanges,
117
- isEditing,
118
- options
113
+ unitId: r,
114
+ subUnitId: o,
115
+ docRanges: e,
116
+ isEditing: n,
117
+ options: s
119
118
  });
120
119
  }
121
120
  // Only use in doc-selection-render.controller.ts
122
- __replaceTextRangesWithNoRefresh(textSelectionInfo) {
121
+ __replaceTextRangesWithNoRefresh(e, t) {
123
122
  if (this._currentSelection == null)
124
123
  return;
125
- const params = {
126
- ...this._currentSelection,
127
- ...textSelectionInfo
124
+ const n = {
125
+ ...e,
126
+ ...t
128
127
  };
129
- this._replaceByParam(params), this._textSelection$.next(params);
130
- const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params, ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0);
131
- this._commandService.executeCommand(SetTextSelectionsOperation.id, {
132
- unitId,
133
- subUnitId,
134
- segmentId,
135
- style,
136
- isEditing,
137
- ranges
128
+ this._replaceByParam(n), this._textSelection$.next(n);
129
+ const { unitId: s, subUnitId: r, segmentId: o, style: c, textRanges: a, rectRanges: l, isEditing: d } = n, _ = [...a, ...l].filter((g) => g.startOffset != null && g.endOffset != null).sort((g, f) => g.startOffset > f.startOffset ? 1 : g.startOffset < f.startOffset ? -1 : 0);
130
+ this._commandService.executeCommand(L.id, {
131
+ unitId: s,
132
+ subUnitId: r,
133
+ segmentId: o,
134
+ style: c,
135
+ isEditing: d,
136
+ ranges: _
138
137
  });
139
138
  }
140
139
  dispose() {
141
140
  this._textSelection$.complete();
142
141
  }
143
- _setCurrentSelectionNotRefresh(param) {
144
- this._currentSelection = param;
142
+ _setCurrentSelectionNotRefresh(e) {
143
+ this._currentSelection = e;
145
144
  }
146
- _getTextRanges(param) {
147
- var _a6;
148
- if (param == null)
145
+ _getTextRanges(e) {
146
+ var s;
147
+ if (e == null)
149
148
  return;
150
- const { unitId, subUnitId = "" } = param;
151
- return (_a6 = this._textSelectionInfo.get(unitId)) == null ? void 0 : _a6.get(subUnitId);
149
+ const { unitId: t, subUnitId: n = "" } = e;
150
+ return (s = this._textSelectionInfo.get(t)) == null ? void 0 : s.get(n);
152
151
  }
153
- _refresh(param) {
154
- const allTextSelectionInfo = this._getTextRanges(param);
155
- if (allTextSelectionInfo == null)
152
+ _refresh(e) {
153
+ const t = this._getTextRanges(e);
154
+ if (t == null)
156
155
  return;
157
- const { textRanges, rectRanges } = allTextSelectionInfo, docRanges = [...textRanges, ...rectRanges], { unitId, subUnitId } = param;
156
+ const { textRanges: n, rectRanges: s } = t, r = [...n, ...s], { unitId: o, subUnitId: c } = e;
158
157
  this._refreshSelection$.next({
159
- unitId,
160
- subUnitId,
161
- docRanges,
158
+ unitId: o,
159
+ subUnitId: c,
160
+ docRanges: r,
162
161
  isEditing: !1
163
162
  });
164
163
  }
165
- _replaceByParam(insertParam) {
166
- const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
167
- this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(unitId).set(subUnitId, { ...selectionInsertParam });
168
- }
169
- _addByParam(insertParam) {
170
- const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
171
- this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map());
172
- const unitTextRange = this._textSelectionInfo.get(unitId);
173
- unitTextRange.has(subUnitId) ? unitTextRange.get(subUnitId).textRanges.push(...insertParam.textRanges) : unitTextRange.set(subUnitId, { ...selectionInsertParam });
174
- }
175
- }, __name(_a, "DocSelectionManagerService"), _a);
176
- DocSelectionManagerService = __decorateClass$4([
177
- __decorateParam$4(0, ICommandService),
178
- __decorateParam$4(1, IUniverInstanceService)
179
- ], DocSelectionManagerService);
180
- var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
181
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
182
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
183
- return kind && result && __defProp$3(target, key, result), result;
184
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a2;
185
- let DocSkeletonManagerService = (_a2 = class extends RxDisposable {
186
- constructor(_context, _localeService, _univerInstanceService) {
164
+ _replaceByParam(e) {
165
+ const { unitId: t, subUnitId: n, ...s } = e;
166
+ this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(n, { ...s });
167
+ }
168
+ _addByParam(e) {
169
+ const { unitId: t, subUnitId: n, ...s } = e;
170
+ this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map());
171
+ const r = this._textSelectionInfo.get(t);
172
+ r.has(n) ? r.get(n).textRanges.push(...e.textRanges) : r.set(n, { ...s });
173
+ }
174
+ };
175
+ v = Oe([
176
+ W(0, A),
177
+ W(1, p)
178
+ ], v);
179
+ var xe = Object.defineProperty, Ce = Object.getOwnPropertyDescriptor, Me = (i, e, t, n) => {
180
+ for (var s = n > 1 ? void 0 : n ? Ce(e, t) : e, r = i.length - 1, o; r >= 0; r--)
181
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
182
+ return n && s && xe(e, t, s), s;
183
+ }, Y = (i, e) => (t, n) => e(t, n, i);
184
+ let b = class extends j {
185
+ constructor(e, t, n) {
187
186
  super();
188
- __publicField(this, "_skeleton");
189
- __publicField(this, "_docViewModel");
190
- __publicField(this, "_currentSkeleton$", new BehaviorSubject(null));
191
- __publicField(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
187
+ u(this, "_skeleton");
188
+ u(this, "_docViewModel");
189
+ u(this, "_currentSkeleton$", new M(null));
190
+ u(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
192
191
  // CurrentSkeletonBefore for pre-triggered logic during registration
193
- __publicField(this, "_currentSkeletonBefore$", new BehaviorSubject(null));
194
- __publicField(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
195
- __publicField(this, "_currentViewModel$", new BehaviorSubject(null));
196
- __publicField(this, "currentViewModel$", this._currentViewModel$.asObservable());
197
- this._context = _context, this._localeService = _localeService, this._univerInstanceService = _univerInstanceService, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
198
- documentModel && documentModel.getUnitId() === this._context.unitId && this._update(documentModel);
192
+ u(this, "_currentSkeletonBefore$", new M(null));
193
+ u(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
194
+ u(this, "_currentViewModel$", new M(null));
195
+ u(this, "currentViewModel$", this._currentViewModel$.asObservable());
196
+ this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(y.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((s) => {
197
+ s && s.getUnitId() === this._context.unitId && this._update(s);
199
198
  });
200
199
  }
201
200
  dispose() {
@@ -208,275 +207,398 @@ let DocSkeletonManagerService = (_a2 = class extends RxDisposable {
208
207
  return this._docViewModel;
209
208
  }
210
209
  _init() {
211
- const documentDataModel = this._context.unit;
212
- this._update(documentDataModel);
210
+ const e = this._context.unit;
211
+ this._update(e);
213
212
  }
214
- _update(documentDataModel) {
215
- const unitId = this._context.unitId;
216
- if (documentDataModel.getBody() == null)
213
+ _update(e) {
214
+ const t = this._context.unitId;
215
+ if (e.getBody() == null)
217
216
  return;
218
- this._docViewModel && isInternalEditorID(unitId) ? (this._docViewModel.reset(documentDataModel), this._context.unit = documentDataModel) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(documentDataModel)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
219
- const skeleton = this._skeleton;
220
- skeleton.calculate(), this._currentSkeletonBefore$.next(skeleton), this._currentSkeleton$.next(skeleton), this._currentViewModel$.next(this._docViewModel);
221
- }
222
- _buildSkeleton(documentViewModel) {
223
- return DocumentSkeleton.create(documentViewModel, this._localeService);
224
- }
225
- _buildDocViewModel(documentDataModel) {
226
- return new DocumentViewModel(documentDataModel);
227
- }
228
- }, __name(_a2, "DocSkeletonManagerService"), _a2);
229
- DocSkeletonManagerService = __decorateClass$3([
230
- __decorateParam$3(1, Inject(LocaleService)),
231
- __decorateParam$3(2, IUniverInstanceService)
232
- ], DocSkeletonManagerService);
233
- const _DocStateEmitService = class _DocStateEmitService extends RxDisposable {
217
+ this._docViewModel && oe(t) ? (this._docViewModel.reset(e), this._context.unit = e) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(e)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
218
+ const n = this._skeleton;
219
+ n.calculate(), this._currentSkeletonBefore$.next(n), this._currentSkeleton$.next(n), this._currentViewModel$.next(this._docViewModel);
220
+ }
221
+ _buildSkeleton(e) {
222
+ return Se.create(e, this._localeService);
223
+ }
224
+ _buildDocViewModel(e) {
225
+ return new pe(e);
226
+ }
227
+ };
228
+ b = Me([
229
+ Y(1, $(re)),
230
+ Y(2, p)
231
+ ], b);
232
+ class ee extends j {
234
233
  constructor() {
235
234
  super();
236
- __publicField(this, "_docStateChangeParams$", new BehaviorSubject(null));
237
- __publicField(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
235
+ u(this, "_docStateChangeParams$", new M(null));
236
+ u(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
238
237
  }
239
- emitStateChangeInfo(params) {
240
- this._docStateChangeParams$.next(params);
238
+ emitStateChangeInfo(t) {
239
+ this._docStateChangeParams$.next(t);
241
240
  }
242
241
  dispose() {
243
242
  super.dispose(), this._docStateChangeParams$.complete();
244
243
  }
245
- };
246
- __name(_DocStateEmitService, "DocStateEmitService");
247
- let DocStateEmitService = _DocStateEmitService;
248
- const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEditingMutation = {
249
- id: RichTextEditingMutationId,
250
- type: CommandType.MUTATION,
244
+ }
245
+ const K = "doc.mutation.rich-text-editing", D = {
246
+ id: K,
247
+ type: B.MUTATION,
251
248
  // eslint-disable-next-line max-lines-per-function
252
- handler: /* @__PURE__ */ __name((accessor, params) => {
253
- var _a6, _b;
249
+ handler: (i, e) => {
250
+ var G, F;
254
251
  const {
255
- unitId,
256
- segmentId = "",
257
- actions,
258
- textRanges,
259
- prevTextRanges,
260
- trigger,
261
- noHistory,
262
- isCompositionEnd,
263
- noNeedSetTextRange,
264
- debounce,
265
- isEditing = !0,
266
- isSync,
267
- syncer
268
- } = params, univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), docStateEmitService = accessor.get(DocStateEmitService), documentDataModel = univerInstanceService.getUniverDocInstance(unitId), documentViewModel = (_a6 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a6.with(DocSkeletonManagerService).getViewModel();
269
- if (documentDataModel == null || documentViewModel == null)
270
- throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);
271
- const docSelectionManagerService = accessor.get(DocSelectionManagerService), docRanges = (_b = docSelectionManagerService.getDocRanges()) != null ? _b : [], disabled = !!documentDataModel.getSnapshot().disabled;
272
- if (JSONX.isNoop(actions) || actions && actions.length === 0 || disabled)
252
+ unitId: t,
253
+ segmentId: n = "",
254
+ actions: s,
255
+ textRanges: r,
256
+ prevTextRanges: o,
257
+ trigger: c,
258
+ noHistory: a,
259
+ isCompositionEnd: l,
260
+ noNeedSetTextRange: d,
261
+ debounce: _,
262
+ isEditing: g = !0,
263
+ isSync: f,
264
+ syncer: I
265
+ } = e, m = i.get(p), h = i.get(Ie), R = i.get(ee), S = m.getUniverDocInstance(t), T = (G = h.getRenderById(t)) == null ? void 0 : G.with(b).getViewModel();
266
+ if (S == null || T == null)
267
+ throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
268
+ const C = i.get(v), U = (F = C.getDocRanges()) != null ? F : [], te = !!S.getSnapshot().disabled;
269
+ if (O.isNoop(s) || s && s.length === 0 || te)
273
270
  return {
274
- unitId,
271
+ unitId: t,
275
272
  actions: [],
276
- textRanges: docRanges
273
+ textRanges: U
277
274
  };
278
- const undoActions = JSONX.invertWithDoc(actions, documentDataModel.getSnapshot());
279
- documentDataModel.apply(actions), documentViewModel.reset(documentDataModel), !noNeedSetTextRange && textRanges && trigger != null && queueMicrotask(() => {
280
- docSelectionManagerService.replaceDocRanges(textRanges, { unitId, subUnitId: unitId }, isEditing, params.options);
275
+ const z = O.invertWithDoc(s, S.getSnapshot());
276
+ S.apply(s), T.reset(S), !d && r && c != null && queueMicrotask(() => {
277
+ C.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
281
278
  });
282
- const changeState = {
283
- commandId: RichTextEditingMutationId,
284
- unitId,
285
- segmentId,
286
- trigger,
287
- noHistory,
288
- debounce,
279
+ const ne = {
280
+ commandId: K,
281
+ unitId: t,
282
+ segmentId: n,
283
+ trigger: c,
284
+ noHistory: a,
285
+ debounce: _,
289
286
  redoState: {
290
- actions,
291
- textRanges
287
+ actions: s,
288
+ textRanges: r
292
289
  },
293
290
  undoState: {
294
- actions: undoActions,
295
- textRanges: prevTextRanges != null ? prevTextRanges : docRanges
291
+ actions: z,
292
+ textRanges: o != null ? o : U
296
293
  },
297
- isCompositionEnd,
298
- isSync,
299
- syncer
294
+ isCompositionEnd: l,
295
+ isSync: f,
296
+ syncer: I
300
297
  };
301
- return docStateEmitService.emitStateChangeInfo(changeState), {
302
- unitId,
303
- actions: undoActions,
304
- textRanges: docRanges
298
+ return R.emitStateChangeInfo(ne), {
299
+ unitId: t,
300
+ actions: z,
301
+ textRanges: U
305
302
  };
306
- }, "handler")
307
- }, DocsRenameMutation = {
303
+ }
304
+ }, De = {
308
305
  id: "doc.mutation.rename-doc",
309
- type: CommandType.MUTATION,
310
- handler: /* @__PURE__ */ __name((accessor, params) => {
311
- const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
312
- return doc ? (doc.setName(params.name), !0) : !1;
313
- }, "handler")
314
- }, PLUGIN_CONFIG_KEY = "docs.config", defaultPluginConfig = {};
315
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
316
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
317
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
318
- return kind && result && __defProp$2(target, key, result), result;
319
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a3;
320
- let DocCustomRangeController = (_a3 = class extends Disposable {
321
- constructor(_commandService, _textSelectionManagerService, _univerInstanceService) {
322
- super(), this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this._initSelectionChange();
323
- }
324
- _transformCustomRange(doc, selection) {
325
- var _a6;
326
- const { startOffset, endOffset, collapsed } = selection, customRanges = (_a6 = doc.getCustomRanges()) == null ? void 0 : _a6.filter((range) => !range.wholeEntity || startOffset <= range.startIndex && endOffset > range.endIndex ? !1 : collapsed ? range.startIndex < startOffset && range.endIndex >= endOffset : BuildTextUtils.range.isIntersects(startOffset, endOffset - 1, range.startIndex, range.endIndex));
327
- if (customRanges != null && customRanges.length) {
328
- let start = startOffset, end = endOffset;
329
- return customRanges.forEach((range) => {
330
- start = Math.min(range.startIndex, start), end = Math.max(range.endIndex + 1, end);
306
+ type: B.MUTATION,
307
+ handler: (i, e) => {
308
+ const n = i.get(p).getUnit(e.unitId, y.UNIVER_DOC);
309
+ return n ? (n.setName(e.name), !0) : !1;
310
+ }
311
+ }, Te = "docs.config", be = {};
312
+ var we = Object.defineProperty, ye = Object.getOwnPropertyDescriptor, $e = (i, e, t, n) => {
313
+ for (var s = n > 1 ? void 0 : n ? ye(e, t) : e, r = i.length - 1, o; r >= 0; r--)
314
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
315
+ return n && s && we(e, t, s), s;
316
+ }, P = (i, e) => (t, n) => e(t, n, i);
317
+ let w = class extends J {
318
+ constructor(i, e, t) {
319
+ super(), this._commandService = i, this._textSelectionManagerService = e, this._univerInstanceService = t, this._initSelectionChange();
320
+ }
321
+ _transformCustomRange(i, e) {
322
+ var o;
323
+ const { startOffset: t, endOffset: n, collapsed: s } = e, r = (o = i.getCustomRanges()) == null ? void 0 : o.filter((c) => !c.wholeEntity || t <= c.startIndex && n > c.endIndex ? !1 : s ? c.startIndex < t && c.endIndex >= n : x.range.isIntersects(t, n - 1, c.startIndex, c.endIndex));
324
+ if (r != null && r.length) {
325
+ let c = t, a = n;
326
+ return r.forEach((l) => {
327
+ c = Math.min(l.startIndex, c), a = Math.max(l.endIndex + 1, a);
331
328
  }), {
332
- ...selection,
333
- startOffset: start,
334
- endOffset: end,
335
- collapsed: start === end
329
+ ...e,
330
+ startOffset: c,
331
+ endOffset: a,
332
+ collapsed: c === a
336
333
  };
337
334
  }
338
- return selection;
335
+ return e;
339
336
  }
340
337
  _initSelectionChange() {
341
- this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
342
- if (commandInfo.id === SetTextSelectionsOperation.id) {
343
- const params = commandInfo.params, { unitId, ranges, isEditing } = params, doc = this._univerInstanceService.getUnit(unitId);
344
- if (!doc)
338
+ this.disposeWithMe(this._commandService.onCommandExecuted((i) => {
339
+ if (i.id === L.id) {
340
+ const e = i.params, { unitId: t, ranges: n, isEditing: s } = e, r = this._univerInstanceService.getUnit(t);
341
+ if (!r)
345
342
  return;
346
- const transformedRanges = ranges.map((range) => this._transformCustomRange(doc, range));
347
- transformedRanges.some((range, i) => ranges[i] !== range) && this._textSelectionManagerService.replaceTextRanges(transformedRanges, isEditing);
343
+ const o = n.map((c) => this._transformCustomRange(r, c));
344
+ o.some((c, a) => n[a] !== c) && this._textSelectionManagerService.replaceTextRanges(o, s);
348
345
  }
349
346
  }));
350
347
  }
351
- }, __name(_a3, "DocCustomRangeController"), _a3);
352
- DocCustomRangeController = __decorateClass$2([
353
- __decorateParam$2(0, ICommandService),
354
- __decorateParam$2(1, Inject(DocSelectionManagerService)),
355
- __decorateParam$2(2, IUniverInstanceService)
356
- ], DocCustomRangeController);
357
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
358
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
359
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
360
- return kind && result && __defProp$1(target, key, result), result;
361
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
362
- const PLUGIN_NAME = "DOCS_PLUGIN";
363
- var _a4;
364
- let UniverDocsPlugin = (_a4 = class extends Plugin {
348
+ };
349
+ w = $e([
350
+ P(0, A),
351
+ P(1, $(v)),
352
+ P(2, p)
353
+ ], w);
354
+ var Ue = Object.defineProperty, Ee = Object.getOwnPropertyDescriptor, Pe = (i, e, t, n) => {
355
+ for (var s = n > 1 ? void 0 : n ? Ee(e, t) : e, r = i.length - 1, o; r >= 0; r--)
356
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
357
+ return n && s && Ue(e, t, s), s;
358
+ }, H = (i, e) => (t, n) => e(t, n, i);
359
+ const Ne = "DOCS_PLUGIN";
360
+ var V;
361
+ let k = (V = class extends ae {
365
362
  // static override type = UniverInstanceType.UNIVER_DOC;
366
- constructor(_config = defaultPluginConfig, _injector, _configService) {
367
- super(), this._config = _config, this._injector = _injector, this._configService = _configService;
368
- const { ...rest } = this._config;
369
- this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
363
+ constructor(i = be, e, t) {
364
+ super(), this._config = i, this._injector = e, this._configService = t;
365
+ const { ...n } = this._config;
366
+ this._configService.setConfig(Te, n);
370
367
  }
371
368
  onStarting() {
372
369
  this._initializeDependencies(), this._initializeCommands();
373
370
  }
374
371
  _initializeCommands() {
375
372
  [
376
- RichTextEditingMutation,
377
- DocsRenameMutation,
378
- SetTextSelectionsOperation
379
- ].forEach((command) => {
380
- this._injector.get(ICommandService).registerCommand(command);
373
+ D,
374
+ De,
375
+ L
376
+ ].forEach((i) => {
377
+ this._injector.get(A).registerCommand(i);
381
378
  });
382
379
  }
383
380
  _initializeDependencies() {
384
381
  [
385
- [DocSelectionManagerService],
386
- [DocStateEmitService],
387
- [DocCustomRangeController]
388
- ].forEach((d) => this._injector.add(d));
382
+ [v],
383
+ [ee],
384
+ [w]
385
+ ].forEach((i) => this._injector.add(i));
389
386
  }
390
387
  onReady() {
391
- this._injector.get(DocCustomRangeController);
392
- }
393
- }, __name(_a4, "UniverDocsPlugin"), __publicField(_a4, "pluginName", PLUGIN_NAME), _a4);
394
- UniverDocsPlugin = __decorateClass$1([
395
- __decorateParam$1(1, Inject(Injector)),
396
- __decorateParam$1(2, IConfigService)
397
- ], UniverDocsPlugin);
398
- const CUSTOM_RANGE = createInterceptorKey("CUSTOM_RANGE"), CUSTOM_DECORATION = createInterceptorKey("CUSTOM_DECORATION"), DOC_INTERCEPTOR_POINT = {
399
- CUSTOM_RANGE,
400
- CUSTOM_DECORATION
388
+ this._injector.get(w);
389
+ }
390
+ }, u(V, "pluginName", Ne), V);
391
+ k = Pe([
392
+ H(1, $(ce)),
393
+ H(2, le)
394
+ ], k);
395
+ const Ve = Q("CUSTOM_RANGE"), Be = Q("CUSTOM_DECORATION"), N = {
396
+ CUSTOM_RANGE: Ve,
397
+ CUSTOM_DECORATION: Be
401
398
  };
402
- var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
403
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
404
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
405
- return kind && result && __defProp2(target, key, result), result;
406
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a5;
407
- let DocInterceptorService = (_a5 = class extends Disposable {
408
- constructor(_context, _docSkeletonManagerService) {
399
+ var je = Object.defineProperty, Ae = Object.getOwnPropertyDescriptor, Le = (i, e, t, n) => {
400
+ for (var s = n > 1 ? void 0 : n ? Ae(e, t) : e, r = i.length - 1, o; r >= 0; r--)
401
+ (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
402
+ return n && s && je(e, t, s), s;
403
+ }, Xe = (i, e) => (t, n) => e(t, n, i);
404
+ let q = class extends J {
405
+ constructor(e, t) {
409
406
  super();
410
- __publicField(this, "_interceptorsByName", /* @__PURE__ */ new Map());
411
- this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService;
412
- const viewModel = this._docSkeletonManagerService.getViewModel(), unitId = viewModel.getDataModel().getUnitId();
413
- if (unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)
407
+ u(this, "_interceptorsByName", /* @__PURE__ */ new Map());
408
+ this._context = e, this._docSkeletonManagerService = t;
409
+ const n = this._docSkeletonManagerService.getViewModel(), s = n.getDataModel().getUnitId();
410
+ if (s === ue || s === de)
414
411
  return;
415
- this.disposeWithMe(this.interceptDocumentViewModel(viewModel)), this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
412
+ this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(N.CUSTOM_RANGE, {
416
413
  priority: -1,
417
- handler: /* @__PURE__ */ __name((data, pos, next) => next(data), "handler")
414
+ handler: (o, c, a) => a(o)
418
415
  }));
419
- let disposableCollection = new DisposableCollection();
420
- viewModel.segmentViewModels$.subscribe((segmentViewModels) => {
421
- disposableCollection.dispose(), disposableCollection = new DisposableCollection(), segmentViewModels.forEach((segmentViewModel) => {
422
- disposableCollection.add(this.interceptDocumentViewModel(segmentViewModel));
416
+ let r = new E();
417
+ n.segmentViewModels$.subscribe((o) => {
418
+ r.dispose(), r = new E(), o.forEach((c) => {
419
+ r.add(this.interceptDocumentViewModel(c));
423
420
  });
424
- }), this.disposeWithMe(disposableCollection);
425
- }
426
- intercept(name, interceptor) {
427
- const key = name;
428
- this._interceptorsByName.has(key) || this._interceptorsByName.set(key, []);
429
- const interceptors = this._interceptorsByName.get(key);
430
- return interceptors.push(interceptor), this._interceptorsByName.set(
431
- key,
432
- interceptors.sort((a, b) => {
433
- var _a6, _b;
434
- return ((_a6 = b.priority) != null ? _a6 : 0) - ((_b = a.priority) != null ? _b : 0);
421
+ }), this.disposeWithMe(r);
422
+ }
423
+ intercept(e, t) {
424
+ const n = e;
425
+ this._interceptorsByName.has(n) || this._interceptorsByName.set(n, []);
426
+ const s = this._interceptorsByName.get(n);
427
+ return s.push(t), this._interceptorsByName.set(
428
+ n,
429
+ s.sort((r, o) => {
430
+ var c, a;
431
+ return ((c = o.priority) != null ? c : 0) - ((a = r.priority) != null ? a : 0);
435
432
  })
436
- ), this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key), interceptor)));
437
- }
438
- fetchThroughInterceptors(name) {
439
- const key = name, interceptors = this._interceptorsByName.get(key);
440
- return composeInterceptors(interceptors || []);
441
- }
442
- interceptDocumentViewModel(viewModel) {
443
- const disposableCollection = new DisposableCollection();
444
- return disposableCollection.add(viewModel.registerCustomRangeInterceptor({
445
- getCustomRange: /* @__PURE__ */ __name((index) => {
446
- var _a6;
447
- return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(
448
- viewModel.getCustomRangeRaw(index),
433
+ ), this.disposeWithMe(ge(() => _e(this._interceptorsByName.get(n), t)));
434
+ }
435
+ fetchThroughInterceptors(e) {
436
+ const t = e, n = this._interceptorsByName.get(t);
437
+ return fe(n || []);
438
+ }
439
+ interceptDocumentViewModel(e) {
440
+ const t = new E();
441
+ return t.add(e.registerCustomRangeInterceptor({
442
+ getCustomRange: (n) => {
443
+ var s;
444
+ return this.fetchThroughInterceptors(N.CUSTOM_RANGE)(
445
+ e.getCustomRangeRaw(n),
449
446
  {
450
- index,
451
- unitId: viewModel.getDataModel().getUnitId(),
452
- customRanges: (_a6 = viewModel.getDataModel().getCustomRanges()) != null ? _a6 : []
447
+ index: n,
448
+ unitId: e.getDataModel().getUnitId(),
449
+ customRanges: (s = e.getDataModel().getCustomRanges()) != null ? s : []
453
450
  }
454
451
  );
455
- }, "getCustomRange"),
456
- getCustomDecoration: /* @__PURE__ */ __name((index) => {
457
- var _a6;
458
- return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(
459
- viewModel.getCustomDecorationRaw(index),
452
+ },
453
+ getCustomDecoration: (n) => {
454
+ var s;
455
+ return this.fetchThroughInterceptors(N.CUSTOM_DECORATION)(
456
+ e.getCustomDecorationRaw(n),
460
457
  {
461
- index,
462
- unitId: viewModel.getDataModel().getUnitId(),
463
- customDecorations: (_a6 = viewModel.getDataModel().getCustomDecorations()) != null ? _a6 : []
458
+ index: n,
459
+ unitId: e.getDataModel().getUnitId(),
460
+ customDecorations: (s = e.getDataModel().getCustomDecorations()) != null ? s : []
464
461
  }
465
462
  );
466
- }, "getCustomDecoration")
467
- })), disposableCollection;
463
+ }
464
+ })), t;
468
465
  }
469
- }, __name(_a5, "DocInterceptorService"), _a5);
470
- DocInterceptorService = __decorateClass([
471
- __decorateParam(1, Inject(DocSkeletonManagerService))
472
- ], DocInterceptorService);
466
+ };
467
+ q = Le([
468
+ Xe(1, $(b))
469
+ ], q);
470
+ function X(i, e = "") {
471
+ if (!e)
472
+ return ["body"];
473
+ const { headers: t, footers: n } = i.getSnapshot();
474
+ if (t == null && n == null)
475
+ throw new Error("Document data model must have headers or footers when update by segment id");
476
+ if ((t == null ? void 0 : t[e]) != null)
477
+ return ["headers", e, "body"];
478
+ if ((n == null ? void 0 : n[e]) != null)
479
+ return ["footers", e, "body"];
480
+ throw new Error("Segment id not found in headers or footers");
481
+ }
482
+ function Ye(i, e, t) {
483
+ const { unitId: n, segmentId: s } = e, o = i.get(p).getUnit(n);
484
+ if (!o)
485
+ return !1;
486
+ const c = {
487
+ id: D.id,
488
+ params: {
489
+ unitId: e.unitId,
490
+ actions: [],
491
+ textRanges: void 0
492
+ }
493
+ }, a = O.getInstance(), l = x.customRange.add({ ...e, body: t });
494
+ if (!l)
495
+ return !1;
496
+ const d = X(o, s);
497
+ return c.params.actions = a.editOp(l.serialize(), d), c;
498
+ }
499
+ function Ke(i, e) {
500
+ var C;
501
+ const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selection: c } = e, a = i.get(v), l = i.get(p), d = c != null ? c : (C = a.getTextRanges({ unitId: o, subUnitId: o })) == null ? void 0 : C[0], _ = d == null ? void 0 : d.segmentId;
502
+ if (!d)
503
+ return !1;
504
+ const g = l.getUnit(o, y.UNIVER_DOC);
505
+ if (!g)
506
+ return !1;
507
+ const f = g.getSelfOrHeaderFooterModel(d.segmentId).getBody();
508
+ if (!f)
509
+ return !1;
510
+ const { startOffset: I, endOffset: m } = x.selection.normalizeSelection(d), h = x.customRange.add({
511
+ range: { startOffset: I, endOffset: m, collapsed: I === m },
512
+ rangeId: t,
513
+ rangeType: n,
514
+ segmentId: _,
515
+ wholeEntity: s,
516
+ properties: r,
517
+ body: f
518
+ });
519
+ if (!h)
520
+ return !1;
521
+ const R = O.getInstance(), S = {
522
+ id: D.id,
523
+ params: {
524
+ unitId: o,
525
+ actions: [],
526
+ textRanges: h.selections
527
+ },
528
+ textX: h
529
+ }, T = X(g, _);
530
+ return S.params.actions = R.editOp(h.serialize(), T), S;
531
+ }
532
+ function He(i, e) {
533
+ const { unitId: t, segmentId: n, insert: s } = e, o = i.get(p).getUnit(t);
534
+ if (!o)
535
+ return !1;
536
+ const c = {
537
+ id: D.id,
538
+ params: {
539
+ unitId: e.unitId,
540
+ actions: [],
541
+ textRanges: void 0,
542
+ segmentId: n
543
+ }
544
+ }, a = O.getInstance(), l = x.customRange.delete(i, {
545
+ documentDataModel: o,
546
+ rangeId: e.rangeId,
547
+ insert: s,
548
+ segmentId: n
549
+ });
550
+ if (!l)
551
+ return !1;
552
+ const d = X(o, n);
553
+ return c.params.actions = a.editOp(l.serialize(), d), c.params.textRanges = l.selections, c;
554
+ }
555
+ function ke(i, e) {
556
+ var I, m, h, R;
557
+ const { unitId: t, body: n, doc: s } = e;
558
+ let r = s;
559
+ if (r || (r = i.get(p).getUnit(t)), !r)
560
+ return !1;
561
+ const o = (I = e.selection) == null ? void 0 : I.segmentId, c = (m = r.getSelfOrHeaderFooterModel(o)) == null ? void 0 : m.getBody();
562
+ if (!c) return !1;
563
+ const a = i.get(v), l = (h = e.selection) != null ? h : a.getActiveTextRange();
564
+ if (!l || !c)
565
+ return !1;
566
+ const d = (R = e.textRanges) != null ? R : [{
567
+ startOffset: l.startOffset + n.dataStream.length,
568
+ endOffset: l.startOffset + n.dataStream.length,
569
+ collapsed: !0,
570
+ segmentId: o
571
+ }], _ = x.selection.replace({
572
+ selection: l,
573
+ body: n,
574
+ doc: r
575
+ });
576
+ if (!_)
577
+ return !1;
578
+ const g = {
579
+ id: D.id,
580
+ params: {
581
+ unitId: t,
582
+ actions: [],
583
+ textRanges: d,
584
+ debounce: !0,
585
+ segmentId: o
586
+ },
587
+ textX: _
588
+ }, f = O.getInstance();
589
+ return g.params.actions = f.editOp(_.serialize()), g;
590
+ }
473
591
  export {
474
- DOC_INTERCEPTOR_POINT,
475
- DocInterceptorService,
476
- DocSelectionManagerService,
477
- DocSkeletonManagerService,
478
- DocStateEmitService,
479
- RichTextEditingMutation,
480
- SetTextSelectionsOperation,
481
- UniverDocsPlugin
592
+ N as DOC_INTERCEPTOR_POINT,
593
+ q as DocInterceptorService,
594
+ v as DocSelectionManagerService,
595
+ b as DocSkeletonManagerService,
596
+ ee as DocStateEmitService,
597
+ D as RichTextEditingMutation,
598
+ L as SetTextSelectionsOperation,
599
+ k as UniverDocsPlugin,
600
+ Ke as addCustomRangeBySelectionFactory,
601
+ Ye as addCustomRangeFactory,
602
+ He as deleteCustomRangeFactory,
603
+ ke as replaceSelectionFactory
482
604
  };
@@ -19,6 +19,8 @@ export { DocInterceptorService } from './services/doc-interceptor/doc-intercepto
19
19
  export { DOC_INTERCEPTOR_POINT } from './services/doc-interceptor/interceptor-const';
20
20
  export { DocSelectionManagerService } from './services/doc-selection-manager.service';
21
21
  export { DocSkeletonManagerService } from './services/doc-skeleton-manager.service';
22
+ export { addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory } from './utils/custom-range-factory';
23
+ export { replaceSelectionFactory } from './utils/replace-selection-factory';
22
24
  export type { IDocStateChangeInfo, IDocStateChangeParams } from './services/doc-state-emit.service';
23
25
  export { DocStateEmitService } from './services/doc-state-emit.service';
24
26
  export { type IRichTextEditingMutationParams, RichTextEditingMutation, } from './commands/mutations/core-editing.mutation';
@@ -50,7 +50,7 @@ export declare class DocSelectionManagerService extends RxDisposable {
50
50
  replaceDocRanges(docRanges: ISuccinctDocRangeParam[], params?: Nullable<IDocSelectionManagerSearchParam>, isEditing?: boolean, options?: {
51
51
  [key: string]: boolean;
52
52
  }): void;
53
- __replaceTextRangesWithNoRefresh(textSelectionInfo: IDocSelectionInnerParam): void;
53
+ __replaceTextRangesWithNoRefresh(textSelectionInfo: IDocSelectionInnerParam, search: IDocSelectionManagerSearchParam): void;
54
54
  dispose(): void;
55
55
  private _setCurrentSelectionNotRefresh;
56
56
  private _getTextRanges;
@@ -0,0 +1,29 @@
1
+ import { CustomRangeType, DocumentDataModel, IAccessor, IAddCustomRangeTextXParam, IDocumentBody, IMutationInfo, ITextRangeParam, Nullable, TextX } from '@univerjs/core';
2
+ import { IRichTextEditingMutationParams } from '../commands/mutations/core-editing.mutation';
3
+ interface IAddCustomRangeParam extends IAddCustomRangeTextXParam {
4
+ unitId: string;
5
+ }
6
+ /**
7
+ * @deprecated This is a duplication from docs-ui to avoid making too much breaking changes.
8
+ */
9
+ export declare function getRichTextEditPath(docDataModel: DocumentDataModel, segmentId?: string): string[];
10
+ export declare function addCustomRangeFactory(accessor: IAccessor, param: IAddCustomRangeParam, body: IDocumentBody): false | IMutationInfo<IRichTextEditingMutationParams>;
11
+ interface IAddCustomRangeFactoryParam {
12
+ rangeId: string;
13
+ rangeType: CustomRangeType;
14
+ wholeEntity?: boolean;
15
+ properties?: Record<string, any>;
16
+ unitId: string;
17
+ selection?: ITextRangeParam;
18
+ }
19
+ export declare function addCustomRangeBySelectionFactory(accessor: IAccessor, param: IAddCustomRangeFactoryParam): false | (IMutationInfo<IRichTextEditingMutationParams> & {
20
+ textX: TextX;
21
+ });
22
+ export interface IDeleteCustomRangeFactoryParams {
23
+ rangeId: string;
24
+ segmentId?: string;
25
+ unitId: string;
26
+ insert?: Nullable<IDocumentBody>;
27
+ }
28
+ export declare function deleteCustomRangeFactory(accessor: IAccessor, params: IDeleteCustomRangeFactoryParams): false | IMutationInfo<IRichTextEditingMutationParams>;
29
+ export {};
@@ -0,0 +1,20 @@
1
+ import { DocumentDataModel, IAccessor, IDocumentBody, IMutationInfo, ITextRangeParam, TextX } from '@univerjs/core';
2
+ import { ITextRangeWithStyle } from '@univerjs/engine-render';
3
+ import { IRichTextEditingMutationParams } from '../commands/mutations/core-editing.mutation';
4
+ export interface IReplaceSelectionFactoryParams {
5
+ unitId: string;
6
+ /**
7
+ * selection to be replaced, if not provided, use the current selection.
8
+ */
9
+ selection?: ITextRangeParam;
10
+ /** Body to be inserted at the given position. */
11
+ body: IDocumentBody;
12
+ /**
13
+ * Text ranges to be replaced.
14
+ */
15
+ textRanges?: ITextRangeWithStyle[];
16
+ doc?: DocumentDataModel;
17
+ }
18
+ export declare function replaceSelectionFactory(accessor: IAccessor, params: IReplaceSelectionFactoryParams): false | (IMutationInfo<IRichTextEditingMutationParams> & {
19
+ textX: TextX;
20
+ });
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverDocs={},global.UniverCore,global.UniverEngineRender,global.rxjs))})(this,function(exports2,core,engineRender,rxjs){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e;const SetTextSelectionsOperation={id:"doc.operation.set-selections",type:core.CommandType.OPERATION,handler:__name(()=>!0,"handler")};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4");exports2.DocSelectionManagerService=(_a=class extends core.RxDisposable{constructor(_commandService,_univerInstanceService){super();__publicField(this,"_currentSelection",null);__publicField(this,"_textSelectionInfo",new Map);__publicField(this,"_textSelection$",new rxjs.Subject);__publicField(this,"textSelection$",this._textSelection$.asObservable());__publicField(this,"_refreshSelection$",new rxjs.BehaviorSubject(null));__publicField(this,"refreshSelection$",this._refreshSelection$.asObservable());this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_DOC).pipe(rxjs.takeUntil(this.dispose$)).subscribe(documentModel=>{if(documentModel==null)return;const unitId=documentModel.getUnitId();this._setCurrentSelectionNotRefresh({unitId,subUnitId:unitId})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(params=this._currentSelection){return this._getTextRanges(params)}refreshSelection(params=this._currentSelection){params!=null&&this._refresh(params)}__TEST_ONLY_setCurrentSelection(param){this._currentSelection=param,this._refresh(param)}getTextRanges(params=this._currentSelection){var _a2;return(_a2=this._getTextRanges(params))==null?void 0:_a2.textRanges}getRectRanges(params=this._currentSelection){var _a2;return(_a2=this._getTextRanges(params))==null?void 0:_a2.rectRanges}getDocRanges(params=this._currentSelection){var _a2,_b2;const textRanges=(_a2=this.getTextRanges(params))!=null?_a2:[],rectRanges=(_b2=this.getRectRanges(params))!=null?_b2:[];return[...textRanges,...rectRanges].filter(range=>range.startOffset!=null&&range.endOffset!=null).sort((a,b)=>a.startOffset>b.startOffset?1:a.startOffset<b.startOffset?-1:0)}getActiveTextRange(){const selectionInfo=this._getTextRanges(this._currentSelection);if(selectionInfo==null)return;const{textRanges}=selectionInfo;return textRanges.find(textRange=>textRange.isActive)}getActiveRectRange(){const selectionInfo=this._getTextRanges(this._currentSelection);if(selectionInfo==null)return;const{rectRanges}=selectionInfo;return rectRanges.find(rectRange=>rectRange.isActive)}__TEST_ONLY_add(textRanges,isEditing=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges,rectRanges:[],segmentId:"",segmentPage:-1,isEditing,style:engineRender.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(docRanges,isEditing=!0,options){return this.replaceDocRanges(docRanges,this._currentSelection,isEditing,options)}replaceDocRanges(docRanges,params=this._currentSelection,isEditing=!0,options){if(params==null)return;const{unitId,subUnitId}=params;this._refreshSelection$.next({unitId,subUnitId,docRanges,isEditing,options})}__replaceTextRangesWithNoRefresh(textSelectionInfo){if(this._currentSelection==null)return;const params={...this._currentSelection,...textSelectionInfo};this._replaceByParam(params),this._textSelection$.next(params);const{unitId,subUnitId,segmentId,style,textRanges,rectRanges,isEditing}=params,ranges=[...textRanges,...rectRanges].filter(range=>range.startOffset!=null&&range.endOffset!=null).sort((a,b)=>a.startOffset>b.startOffset?1:a.startOffset<b.startOffset?-1:0);this._commandService.executeCommand(SetTextSelectionsOperation.id,{unitId,subUnitId,segmentId,style,isEditing,ranges})}dispose(){this._textSelection$.complete()}_setCurrentSelectionNotRefresh(param){this._currentSelection=param}_getTextRanges(param){var _a2;if(param==null)return;const{unitId,subUnitId=""}=param;return(_a2=this._textSelectionInfo.get(unitId))==null?void 0:_a2.get(subUnitId)}_refresh(param){const allTextSelectionInfo=this._getTextRanges(param);if(allTextSelectionInfo==null)return;const{textRanges,rectRanges}=allTextSelectionInfo,docRanges=[...textRanges,...rectRanges],{unitId,subUnitId}=param;this._refreshSelection$.next({unitId,subUnitId,docRanges,isEditing:!1})}_replaceByParam(insertParam){const{unitId,subUnitId,...selectionInsertParam}=insertParam;this._textSelectionInfo.has(unitId)||this._textSelectionInfo.set(unitId,new Map),this._textSelectionInfo.get(unitId).set(subUnitId,{...selectionInsertParam})}_addByParam(insertParam){const{unitId,subUnitId,...selectionInsertParam}=insertParam;this._textSelectionInfo.has(unitId)||this._textSelectionInfo.set(unitId,new Map);const unitTextRange=this._textSelectionInfo.get(unitId);unitTextRange.has(subUnitId)?unitTextRange.get(subUnitId).textRanges.push(...insertParam.textRanges):unitTextRange.set(subUnitId,{...selectionInsertParam})}},__name(_a,"DocSelectionManagerService"),_a),exports2.DocSelectionManagerService=__decorateClass$4([__decorateParam$4(0,core.ICommandService),__decorateParam$4(1,core.IUniverInstanceService)],exports2.DocSelectionManagerService);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");exports2.DocSkeletonManagerService=(_b=class extends core.RxDisposable{constructor(_context,_localeService,_univerInstanceService){super();__publicField(this,"_skeleton");__publicField(this,"_docViewModel");__publicField(this,"_currentSkeleton$",new rxjs.BehaviorSubject(null));__publicField(this,"currentSkeleton$",this._currentSkeleton$.asObservable());__publicField(this,"_currentSkeletonBefore$",new rxjs.BehaviorSubject(null));__publicField(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());__publicField(this,"_currentViewModel$",new rxjs.BehaviorSubject(null));__publicField(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=_context,this._localeService=_localeService,this._univerInstanceService=_univerInstanceService,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_DOC).pipe(rxjs.takeUntil(this.dispose$)).subscribe(documentModel=>{documentModel&&documentModel.getUnitId()===this._context.unitId&&this._update(documentModel)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const documentDataModel=this._context.unit;this._update(documentDataModel)}_update(documentDataModel){const unitId=this._context.unitId;if(documentDataModel.getBody()==null)return;this._docViewModel&&core.isInternalEditorID(unitId)?(this._docViewModel.reset(documentDataModel),this._context.unit=documentDataModel):this._docViewModel||(this._docViewModel=this._buildDocViewModel(documentDataModel)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));const skeleton=this._skeleton;skeleton.calculate(),this._currentSkeletonBefore$.next(skeleton),this._currentSkeleton$.next(skeleton),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(documentViewModel){return engineRender.DocumentSkeleton.create(documentViewModel,this._localeService)}_buildDocViewModel(documentDataModel){return new engineRender.DocumentViewModel(documentDataModel)}},__name(_b,"DocSkeletonManagerService"),_b),exports2.DocSkeletonManagerService=__decorateClass$3([__decorateParam$3(1,core.Inject(core.LocaleService)),__decorateParam$3(2,core.IUniverInstanceService)],exports2.DocSkeletonManagerService);const _DocStateEmitService=class _DocStateEmitService extends core.RxDisposable{constructor(){super();__publicField(this,"_docStateChangeParams$",new rxjs.BehaviorSubject(null));__publicField(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(params){this._docStateChangeParams$.next(params)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}};__name(_DocStateEmitService,"DocStateEmitService");let DocStateEmitService=_DocStateEmitService;const RichTextEditingMutationId="doc.mutation.rich-text-editing",RichTextEditingMutation={id:RichTextEditingMutationId,type:core.CommandType.MUTATION,handler:__name((accessor,params)=>{var _a2,_b2;const{unitId,segmentId="",actions,textRanges,prevTextRanges,trigger,noHistory,isCompositionEnd,noNeedSetTextRange,debounce,isEditing=!0,isSync,syncer}=params,univerInstanceService=accessor.get(core.IUniverInstanceService),renderManagerService=accessor.get(engineRender.IRenderManagerService),docStateEmitService=accessor.get(DocStateEmitService),documentDataModel=univerInstanceService.getUniverDocInstance(unitId),documentViewModel=(_a2=renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(exports2.DocSkeletonManagerService).getViewModel();if(documentDataModel==null||documentViewModel==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);const docSelectionManagerService=accessor.get(exports2.DocSelectionManagerService),docRanges=(_b2=docSelectionManagerService.getDocRanges())!=null?_b2:[],disabled=!!documentDataModel.getSnapshot().disabled;if(core.JSONX.isNoop(actions)||actions&&actions.length===0||disabled)return{unitId,actions:[],textRanges:docRanges};const undoActions=core.JSONX.invertWithDoc(actions,documentDataModel.getSnapshot());documentDataModel.apply(actions),documentViewModel.reset(documentDataModel),!noNeedSetTextRange&&textRanges&&trigger!=null&&queueMicrotask(()=>{docSelectionManagerService.replaceDocRanges(textRanges,{unitId,subUnitId:unitId},isEditing,params.options)});const changeState={commandId:RichTextEditingMutationId,unitId,segmentId,trigger,noHistory,debounce,redoState:{actions,textRanges},undoState:{actions:undoActions,textRanges:prevTextRanges!=null?prevTextRanges:docRanges},isCompositionEnd,isSync,syncer};return docStateEmitService.emitStateChangeInfo(changeState),{unitId,actions:undoActions,textRanges:docRanges}},"handler")},DocsRenameMutation={id:"doc.mutation.rename-doc",type:core.CommandType.MUTATION,handler:__name((accessor,params)=>{const doc=accessor.get(core.IUniverInstanceService).getUnit(params.unitId,core.UniverInstanceType.UNIVER_DOC);return doc?(doc.setName(params.name),!0):!1},"handler")},PLUGIN_CONFIG_KEY="docs.config",defaultPluginConfig={};var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let DocCustomRangeController=(_c=class extends core.Disposable{constructor(_commandService,_textSelectionManagerService,_univerInstanceService){super(),this._commandService=_commandService,this._textSelectionManagerService=_textSelectionManagerService,this._univerInstanceService=_univerInstanceService,this._initSelectionChange()}_transformCustomRange(doc,selection){var _a2;const{startOffset,endOffset,collapsed}=selection,customRanges=(_a2=doc.getCustomRanges())==null?void 0:_a2.filter(range=>!range.wholeEntity||startOffset<=range.startIndex&&endOffset>range.endIndex?!1:collapsed?range.startIndex<startOffset&&range.endIndex>=endOffset:core.BuildTextUtils.range.isIntersects(startOffset,endOffset-1,range.startIndex,range.endIndex));if(customRanges!=null&&customRanges.length){let start=startOffset,end=endOffset;return customRanges.forEach(range=>{start=Math.min(range.startIndex,start),end=Math.max(range.endIndex+1,end)}),{...selection,startOffset:start,endOffset:end,collapsed:start===end}}return selection}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===SetTextSelectionsOperation.id){const params=commandInfo.params,{unitId,ranges,isEditing}=params,doc=this._univerInstanceService.getUnit(unitId);if(!doc)return;const transformedRanges=ranges.map(range=>this._transformCustomRange(doc,range));transformedRanges.some((range,i)=>ranges[i]!==range)&&this._textSelectionManagerService.replaceTextRanges(transformedRanges,isEditing)}}))}},__name(_c,"DocCustomRangeController"),_c);DocCustomRangeController=__decorateClass$2([__decorateParam$2(0,core.ICommandService),__decorateParam$2(1,core.Inject(exports2.DocSelectionManagerService)),__decorateParam$2(2,core.IUniverInstanceService)],DocCustomRangeController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");const PLUGIN_NAME="DOCS_PLUGIN";exports2.UniverDocsPlugin=(_d=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[RichTextEditingMutation,DocsRenameMutation,SetTextSelectionsOperation].forEach(command=>{this._injector.get(core.ICommandService).registerCommand(command)})}_initializeDependencies(){[[exports2.DocSelectionManagerService],[DocStateEmitService],[DocCustomRangeController]].forEach(d=>this._injector.add(d))}onReady(){this._injector.get(DocCustomRangeController)}},__name(_d,"UniverDocsPlugin"),__publicField(_d,"pluginName",PLUGIN_NAME),_d),exports2.UniverDocsPlugin=__decorateClass$1([__decorateParam$1(1,core.Inject(core.Injector)),__decorateParam$1(2,core.IConfigService)],exports2.UniverDocsPlugin);const CUSTOM_RANGE=core.createInterceptorKey("CUSTOM_RANGE"),CUSTOM_DECORATION=core.createInterceptorKey("CUSTOM_DECORATION"),DOC_INTERCEPTOR_POINT={CUSTOM_RANGE,CUSTOM_DECORATION};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");exports2.DocInterceptorService=(_e=class extends core.Disposable{constructor(_context,_docSkeletonManagerService){super();__publicField(this,"_interceptorsByName",new Map);this._context=_context,this._docSkeletonManagerService=_docSkeletonManagerService;const viewModel=this._docSkeletonManagerService.getViewModel(),unitId=viewModel.getDataModel().getUnitId();if(unitId===core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||unitId===core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(viewModel)),this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{priority:-1,handler:__name((data,pos,next)=>next(data),"handler")}));let disposableCollection=new core.DisposableCollection;viewModel.segmentViewModels$.subscribe(segmentViewModels=>{disposableCollection.dispose(),disposableCollection=new core.DisposableCollection,segmentViewModels.forEach(segmentViewModel=>{disposableCollection.add(this.interceptDocumentViewModel(segmentViewModel))})}),this.disposeWithMe(disposableCollection)}intercept(name,interceptor){const key=name;this._interceptorsByName.has(key)||this._interceptorsByName.set(key,[]);const interceptors=this._interceptorsByName.get(key);return interceptors.push(interceptor),this._interceptorsByName.set(key,interceptors.sort((a,b)=>{var _a2,_b2;return((_a2=b.priority)!=null?_a2:0)-((_b2=a.priority)!=null?_b2:0)})),this.disposeWithMe(core.toDisposable(()=>core.remove(this._interceptorsByName.get(key),interceptor)))}fetchThroughInterceptors(name){const key=name,interceptors=this._interceptorsByName.get(key);return core.composeInterceptors(interceptors||[])}interceptDocumentViewModel(viewModel){const disposableCollection=new core.DisposableCollection;return disposableCollection.add(viewModel.registerCustomRangeInterceptor({getCustomRange:__name(index=>{var _a2;return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(viewModel.getCustomRangeRaw(index),{index,unitId:viewModel.getDataModel().getUnitId(),customRanges:(_a2=viewModel.getDataModel().getCustomRanges())!=null?_a2:[]})},"getCustomRange"),getCustomDecoration:__name(index=>{var _a2;return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(viewModel.getCustomDecorationRaw(index),{index,unitId:viewModel.getDataModel().getUnitId(),customDecorations:(_a2=viewModel.getDataModel().getCustomDecorations())!=null?_a2:[]})},"getCustomDecoration")})),disposableCollection}},__name(_e,"DocInterceptorService"),_e),exports2.DocInterceptorService=__decorateClass([__decorateParam(1,core.Inject(exports2.DocSkeletonManagerService))],exports2.DocInterceptorService),exports2.DOC_INTERCEPTOR_POINT=DOC_INTERCEPTOR_POINT,exports2.DocStateEmitService=DocStateEmitService,exports2.RichTextEditingMutation=RichTextEditingMutation,exports2.SetTextSelectionsOperation=SetTextSelectionsOperation,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l.UniverDocs={},l.UniverCore,l.UniverEngineRender,l.rxjs))})(this,function(l,r,v,R){"use strict";var Se=Object.defineProperty;var Ie=(l,r,v)=>r in l?Se(l,r,{enumerable:!0,configurable:!0,writable:!0,value:v}):l[r]=v;var g=(l,r,v)=>Ie(l,typeof r!="symbol"?r+"":r,v);var E;const T={id:"doc.operation.set-selections",type:r.CommandType.OPERATION,handler:()=>!0};var L=Object.defineProperty,z=Object.getOwnPropertyDescriptor,G=(c,i,e,t)=>{for(var n=t>1?void 0:t?z(i,e):i,s=c.length-1,o;s>=0;s--)(o=c[s])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&L(i,e,n),n},$=(c,i)=>(e,t)=>i(e,t,c);l.DocSelectionManagerService=class extends r.RxDisposable{constructor(e,t){super();g(this,"_currentSelection",null);g(this,"_textSelectionInfo",new Map);g(this,"_textSelection$",new R.Subject);g(this,"textSelection$",this._textSelection$.asObservable());g(this,"_refreshSelection$",new R.BehaviorSubject(null));g(this,"refreshSelection$",this._refreshSelection$.asObservable());this._commandService=e,this._univerInstanceService=t,this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(r.UniverInstanceType.UNIVER_DOC).pipe(R.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=e.getUnitId();this._setCurrentSelectionNotRefresh({unitId:t,subUnitId:t})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(e=this._currentSelection){return this._getTextRanges(e)}refreshSelection(e=this._currentSelection){e!=null&&this._refresh(e)}__TEST_ONLY_setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}getTextRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.textRanges}getRectRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.rectRanges}getDocRanges(e=this._currentSelection){var o,a;const t=(o=this.getTextRanges(e))!=null?o:[],n=(a=this.getRectRanges(e))!=null?a:[];return[...t,...n].filter(u=>u.startOffset!=null&&u.endOffset!=null).sort((u,d)=>u.startOffset>d.startOffset?1:u.startOffset<d.startOffset?-1:0)}getActiveTextRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t}=e;return t.find(n=>n.isActive)}getActiveRectRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{rectRanges:t}=e;return t.find(n=>n.isActive)}__TEST_ONLY_add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:"",segmentPage:-1,isEditing:t,style:v.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,s){if(t==null)return;const{unitId:o,subUnitId:a}=t;this._refreshSelection$.next({unitId:o,subUnitId:a,docRanges:e,isEditing:n,options:s})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;const n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:s,subUnitId:o,segmentId:a,style:u,textRanges:d,rectRanges:_,isEditing:h}=n,S=[...d,..._].filter(f=>f.startOffset!=null&&f.endOffset!=null).sort((f,I)=>f.startOffset>I.startOffset?1:f.startOffset<I.startOffset?-1:0);this._commandService.executeCommand(T.id,{unitId:s,subUnitId:o,segmentId:a,style:u,isEditing:h,ranges:S})}dispose(){this._textSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_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);if(t==null)return;const{textRanges:n,rectRanges:s}=t,o=[...n,...s],{unitId:a,subUnitId:u}=e;this._refreshSelection$.next({unitId:a,subUnitId:u,docRanges:o,isEditing:!1})}_replaceByParam(e){const{unitId:t,subUnitId:n,...s}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...s})}_addByParam(e){const{unitId:t,subUnitId:n,...s}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const o=this._textSelectionInfo.get(t);o.has(n)?o.get(n).textRanges.push(...e.textRanges):o.set(n,{...s})}},l.DocSelectionManagerService=G([$(0,r.ICommandService),$(1,r.IUniverInstanceService)],l.DocSelectionManagerService);var k=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(c,i,e,t)=>{for(var n=t>1?void 0:t?W(i,e):i,s=c.length-1,o;s>=0;s--)(o=c[s])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&k(i,e,n),n},B=(c,i)=>(e,t)=>i(e,t,c);l.DocSkeletonManagerService=class extends r.RxDisposable{constructor(e,t,n){super();g(this,"_skeleton");g(this,"_docViewModel");g(this,"_currentSkeleton$",new R.BehaviorSubject(null));g(this,"currentSkeleton$",this._currentSkeleton$.asObservable());g(this,"_currentSkeletonBefore$",new R.BehaviorSubject(null));g(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());g(this,"_currentViewModel$",new R.BehaviorSubject(null));g(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=e,this._localeService=t,this._univerInstanceService=n,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(r.UniverInstanceType.UNIVER_DOC).pipe(R.takeUntil(this.dispose$)).subscribe(s=>{s&&s.getUnitId()===this._context.unitId&&this._update(s)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const e=this._context.unit;this._update(e)}_update(e){const t=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&r.isInternalEditorID(t)?(this._docViewModel.reset(e),this._context.unit=e):this._docViewModel||(this._docViewModel=this._buildDocViewModel(e)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));const n=this._skeleton;n.calculate(),this._currentSkeletonBefore$.next(n),this._currentSkeleton$.next(n),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return v.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new v.DocumentViewModel(e)}},l.DocSkeletonManagerService=J([B(1,r.Inject(r.LocaleService)),B(2,r.IUniverInstanceService)],l.DocSkeletonManagerService);class y extends r.RxDisposable{constructor(){super();g(this,"_docStateChangeParams$",new R.BehaviorSubject(null));g(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const j="doc.mutation.rich-text-editing",D={id:j,type:r.CommandType.MUTATION,handler:(c,i)=>{var X,F;const{unitId:e,segmentId:t="",actions:n,textRanges:s,prevTextRanges:o,trigger:a,noHistory:u,isCompositionEnd:d,noNeedSetTextRange:_,debounce:h,isEditing:S=!0,isSync:f,syncer:I}=i,O=c.get(r.IUniverInstanceService),p=c.get(v.IRenderManagerService),M=c.get(y),m=O.getUniverDocInstance(e),b=(X=p.getRenderById(e))==null?void 0:X.with(l.DocSkeletonManagerService).getViewModel();if(m==null||b==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const C=c.get(l.DocSelectionManagerService),N=(F=C.getDocRanges())!=null?F:[],fe=!!m.getSnapshot().disabled;if(r.JSONX.isNoop(n)||n&&n.length===0||fe)return{unitId:e,actions:[],textRanges:N};const A=r.JSONX.invertWithDoc(n,m.getSnapshot());m.apply(n),b.reset(m),!_&&s&&a!=null&&queueMicrotask(()=>{C.replaceDocRanges(s,{unitId:e,subUnitId:e},S,i.options)});const he={commandId:j,unitId:e,segmentId:t,trigger:a,noHistory:u,debounce:h,redoState:{actions:n,textRanges:s},undoState:{actions:A,textRanges:o!=null?o:N},isCompositionEnd:d,isSync:f,syncer:I};return M.emitStateChangeInfo(he),{unitId:e,actions:A,textRanges:N}}},Y={id:"doc.mutation.rename-doc",type:r.CommandType.MUTATION,handler:(c,i)=>{const t=c.get(r.IUniverInstanceService).getUnit(i.unitId,r.UniverInstanceType.UNIVER_DOC);return t?(t.setName(i.name),!0):!1}},K="docs.config",q={};var H=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,Z=(c,i,e,t)=>{for(var n=t>1?void 0:t?Q(i,e):i,s=c.length-1,o;s>=0;s--)(o=c[s])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&H(i,e,n),n},w=(c,i)=>(e,t)=>i(e,t,c);let x=class extends r.Disposable{constructor(c,i,e){super(),this._commandService=c,this._textSelectionManagerService=i,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(c,i){var o;const{startOffset:e,endOffset:t,collapsed:n}=i,s=(o=c.getCustomRanges())==null?void 0:o.filter(a=>!a.wholeEntity||e<=a.startIndex&&t>a.endIndex?!1:n?a.startIndex<e&&a.endIndex>=t:r.BuildTextUtils.range.isIntersects(e,t-1,a.startIndex,a.endIndex));if(s!=null&&s.length){let a=e,u=t;return s.forEach(d=>{a=Math.min(d.startIndex,a),u=Math.max(d.endIndex+1,u)}),{...i,startOffset:a,endOffset:u,collapsed:a===u}}return i}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(c=>{if(c.id===T.id){const i=c.params,{unitId:e,ranges:t,isEditing:n}=i,s=this._univerInstanceService.getUnit(e);if(!s)return;const o=t.map(a=>this._transformCustomRange(s,a));o.some((a,u)=>t[u]!==a)&&this._textSelectionManagerService.replaceTextRanges(o,n)}}))}};x=Z([w(0,r.ICommandService),w(1,r.Inject(l.DocSelectionManagerService)),w(2,r.IUniverInstanceService)],x);var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(c,i,e,t)=>{for(var n=t>1?void 0:t?te(i,e):i,s=c.length-1,o;s>=0;s--)(o=c[s])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&ee(i,e,n),n},V=(c,i)=>(e,t)=>i(e,t,c);const ie="DOCS_PLUGIN";l.UniverDocsPlugin=(E=class extends r.Plugin{constructor(i=q,e,t){super(),this._config=i,this._injector=e,this._configService=t;const{...n}=this._config;this._configService.setConfig(K,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[D,Y,T].forEach(i=>{this._injector.get(r.ICommandService).registerCommand(i)})}_initializeDependencies(){[[l.DocSelectionManagerService],[y],[x]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(x)}},g(E,"pluginName",ie),E),l.UniverDocsPlugin=ne([V(1,r.Inject(r.Injector)),V(2,r.IConfigService)],l.UniverDocsPlugin);const se=r.createInterceptorKey("CUSTOM_RANGE"),re=r.createInterceptorKey("CUSTOM_DECORATION"),U={CUSTOM_RANGE:se,CUSTOM_DECORATION:re};var oe=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,ae=(c,i,e,t)=>{for(var n=t>1?void 0:t?ce(i,e):i,s=c.length-1,o;s>=0;s--)(o=c[s])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&oe(i,e,n),n},le=(c,i)=>(e,t)=>i(e,t,c);l.DocInterceptorService=class extends r.Disposable{constructor(e,t){super();g(this,"_interceptorsByName",new Map);this._context=e,this._docSkeletonManagerService=t;const n=this._docSkeletonManagerService.getViewModel(),s=n.getDataModel().getUnitId();if(s===r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||s===r.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(n)),this.disposeWithMe(this.intercept(U.CUSTOM_RANGE,{priority:-1,handler:(a,u,d)=>d(a)}));let o=new r.DisposableCollection;n.segmentViewModels$.subscribe(a=>{o.dispose(),o=new r.DisposableCollection,a.forEach(u=>{o.add(this.interceptDocumentViewModel(u))})}),this.disposeWithMe(o)}intercept(e,t){const n=e;this._interceptorsByName.has(n)||this._interceptorsByName.set(n,[]);const s=this._interceptorsByName.get(n);return s.push(t),this._interceptorsByName.set(n,s.sort((o,a)=>{var u,d;return((u=a.priority)!=null?u:0)-((d=o.priority)!=null?d:0)})),this.disposeWithMe(r.toDisposable(()=>r.remove(this._interceptorsByName.get(n),t)))}fetchThroughInterceptors(e){const t=e,n=this._interceptorsByName.get(t);return r.composeInterceptors(n||[])}interceptDocumentViewModel(e){const t=new r.DisposableCollection;return t.add(e.registerCustomRangeInterceptor({getCustomRange:n=>{var s;return this.fetchThroughInterceptors(U.CUSTOM_RANGE)(e.getCustomRangeRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customRanges:(s=e.getDataModel().getCustomRanges())!=null?s:[]})},getCustomDecoration:n=>{var s;return this.fetchThroughInterceptors(U.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(s=e.getDataModel().getCustomDecorations())!=null?s:[]})}})),t}},l.DocInterceptorService=ae([le(1,r.Inject(l.DocSkeletonManagerService))],l.DocInterceptorService);function P(c,i=""){if(!i)return["body"];const{headers:e,footers:t}=c.getSnapshot();if(e==null&&t==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[i])!=null)return["headers",i,"body"];if((t==null?void 0:t[i])!=null)return["footers",i,"body"];throw new Error("Segment id not found in headers or footers")}function ue(c,i,e){const{unitId:t,segmentId:n}=i,o=c.get(r.IUniverInstanceService).getUnit(t);if(!o)return!1;const a={id:D.id,params:{unitId:i.unitId,actions:[],textRanges:void 0}},u=r.JSONX.getInstance(),d=r.BuildTextUtils.customRange.add({...i,body:e});if(!d)return!1;const _=P(o,n);return a.params.actions=u.editOp(d.serialize(),_),a}function de(c,i){var C;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:o,selection:a}=i,u=c.get(l.DocSelectionManagerService),d=c.get(r.IUniverInstanceService),_=a!=null?a:(C=u.getTextRanges({unitId:o,subUnitId:o}))==null?void 0:C[0],h=_==null?void 0:_.segmentId;if(!_)return!1;const S=d.getUnit(o,r.UniverInstanceType.UNIVER_DOC);if(!S)return!1;const f=S.getSelfOrHeaderFooterModel(_.segmentId).getBody();if(!f)return!1;const{startOffset:I,endOffset:O}=r.BuildTextUtils.selection.normalizeSelection(_),p=r.BuildTextUtils.customRange.add({range:{startOffset:I,endOffset:O,collapsed:I===O},rangeId:e,rangeType:t,segmentId:h,wholeEntity:n,properties:s,body:f});if(!p)return!1;const M=r.JSONX.getInstance(),m={id:D.id,params:{unitId:o,actions:[],textRanges:p.selections},textX:p},b=P(S,h);return m.params.actions=M.editOp(p.serialize(),b),m}function ge(c,i){const{unitId:e,segmentId:t,insert:n}=i,o=c.get(r.IUniverInstanceService).getUnit(e);if(!o)return!1;const a={id:D.id,params:{unitId:i.unitId,actions:[],textRanges:void 0,segmentId:t}},u=r.JSONX.getInstance(),d=r.BuildTextUtils.customRange.delete(c,{documentDataModel:o,rangeId:i.rangeId,insert:n,segmentId:t});if(!d)return!1;const _=P(o,t);return a.params.actions=u.editOp(d.serialize(),_),a.params.textRanges=d.selections,a}function _e(c,i){var I,O,p,M;const{unitId:e,body:t,doc:n}=i;let s=n;if(s||(s=c.get(r.IUniverInstanceService).getUnit(e)),!s)return!1;const o=(I=i.selection)==null?void 0:I.segmentId,a=(O=s.getSelfOrHeaderFooterModel(o))==null?void 0:O.getBody();if(!a)return!1;const u=c.get(l.DocSelectionManagerService),d=(p=i.selection)!=null?p:u.getActiveTextRange();if(!d||!a)return!1;const _=(M=i.textRanges)!=null?M:[{startOffset:d.startOffset+t.dataStream.length,endOffset:d.startOffset+t.dataStream.length,collapsed:!0,segmentId:o}],h=r.BuildTextUtils.selection.replace({selection:d,body:t,doc:s});if(!h)return!1;const S={id:D.id,params:{unitId:e,actions:[],textRanges:_,debounce:!0,segmentId:o},textX:h},f=r.JSONX.getInstance();return S.params.actions=f.editOp(h.serialize()),S}l.DOC_INTERCEPTOR_POINT=U,l.DocStateEmitService=y,l.RichTextEditingMutation=D,l.SetTextSelectionsOperation=T,l.addCustomRangeBySelectionFactory=de,l.addCustomRangeFactory=ue,l.deleteCustomRangeFactory=ge,l.replaceSelectionFactory=_e,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.4.2",
3
+ "version": "0.5.0-beta.0",
4
4
  "private": false,
5
5
  "description": "UniverSheet normal base-docs",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -33,8 +33,7 @@
33
33
  },
34
34
  "./lib/*": "./lib/*"
35
35
  },
36
- "main": "./lib/cjs/index.js",
37
- "module": "./lib/es/index.js",
36
+ "main": "./lib/es/index.js",
38
37
  "types": "./lib/types/index.d.ts",
39
38
  "publishConfig": {
40
39
  "access": "public"
@@ -49,17 +48,17 @@
49
48
  "rxjs": ">=7.0.0"
50
49
  },
51
50
  "dependencies": {
52
- "@univerjs/core": "0.4.2",
53
- "@univerjs/engine-render": "0.4.2"
51
+ "@univerjs/core": "0.5.0-beta.0",
52
+ "@univerjs/engine-render": "0.5.0-beta.0"
54
53
  },
55
54
  "devDependencies": {
56
55
  "rxjs": "^7.8.1",
57
56
  "typescript": "^5.6.3",
58
- "vite": "^5.4.8",
59
- "vitest": "^2.1.2",
60
- "@univerjs-infra/shared": "0.4.2"
57
+ "vite": "^5.4.11",
58
+ "vitest": "^2.1.5",
59
+ "@univerjs-infra/shared": "0.5.0-beta.0"
61
60
  },
62
- "univerSpace": {
61
+ "space": {
63
62
  ".": {
64
63
  "import": "./lib/es/index.js",
65
64
  "require": "./lib/cjs/index.js",
@@ -77,6 +76,7 @@
77
76
  "test:watch": "vitest",
78
77
  "coverage": "vitest run --coverage",
79
78
  "lint:types": "tsc --noEmit",
80
- "build": "tsc && vite build"
81
- }
79
+ "build": "univer-cli build"
80
+ },
81
+ "module": "./lib/es/index.js"
82
82
  }