@univerjs/docs 0.4.1 → 0.4.2
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}=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.replaceTextRanges(textRanges,isEditing,params.options)});const changeState={commandId:RichTextEditingMutationId,unitId,segmentId,trigger,noHistory,debounce,redoState:{actions,textRanges},undoState:{actions:undoActions,textRanges:prevTextRanges!=null?prevTextRanges:docRanges},isCompositionEnd};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 __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;
|
package/lib/es/index.js
CHANGED
|
@@ -248,6 +248,7 @@ let DocStateEmitService = _DocStateEmitService;
|
|
|
248
248
|
const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEditingMutation = {
|
|
249
249
|
id: RichTextEditingMutationId,
|
|
250
250
|
type: CommandType.MUTATION,
|
|
251
|
+
// eslint-disable-next-line max-lines-per-function
|
|
251
252
|
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
252
253
|
var _a6, _b;
|
|
253
254
|
const {
|
|
@@ -261,7 +262,9 @@ const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEdit
|
|
|
261
262
|
isCompositionEnd,
|
|
262
263
|
noNeedSetTextRange,
|
|
263
264
|
debounce,
|
|
264
|
-
isEditing = !0
|
|
265
|
+
isEditing = !0,
|
|
266
|
+
isSync,
|
|
267
|
+
syncer
|
|
265
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();
|
|
266
269
|
if (documentDataModel == null || documentViewModel == null)
|
|
267
270
|
throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);
|
|
@@ -274,7 +277,7 @@ const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEdit
|
|
|
274
277
|
};
|
|
275
278
|
const undoActions = JSONX.invertWithDoc(actions, documentDataModel.getSnapshot());
|
|
276
279
|
documentDataModel.apply(actions), documentViewModel.reset(documentDataModel), !noNeedSetTextRange && textRanges && trigger != null && queueMicrotask(() => {
|
|
277
|
-
docSelectionManagerService.
|
|
280
|
+
docSelectionManagerService.replaceDocRanges(textRanges, { unitId, subUnitId: unitId }, isEditing, params.options);
|
|
278
281
|
});
|
|
279
282
|
const changeState = {
|
|
280
283
|
commandId: RichTextEditingMutationId,
|
|
@@ -291,7 +294,9 @@ const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEdit
|
|
|
291
294
|
actions: undoActions,
|
|
292
295
|
textRanges: prevTextRanges != null ? prevTextRanges : docRanges
|
|
293
296
|
},
|
|
294
|
-
isCompositionEnd
|
|
297
|
+
isCompositionEnd,
|
|
298
|
+
isSync,
|
|
299
|
+
syncer
|
|
295
300
|
};
|
|
296
301
|
return docStateEmitService.emitStateChangeInfo(changeState), {
|
|
297
302
|
unitId,
|
|
@@ -15,6 +15,7 @@ export interface IRichTextEditingMutationParams extends IMutationCommonParams {
|
|
|
15
15
|
};
|
|
16
16
|
isSync?: boolean;
|
|
17
17
|
isEditing?: boolean;
|
|
18
|
+
syncer?: string;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* The core mutator to change rich text actions. The execution result would be undo mutation params. Could be directly
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JSONXActions, Nullable, RxDisposable } from '@univerjs/core';
|
|
2
2
|
import { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
3
3
|
interface IDocChangeState {
|
|
4
4
|
actions: JSONXActions;
|
|
@@ -16,6 +16,8 @@ export interface IDocStateChangeParams {
|
|
|
16
16
|
}
|
|
17
17
|
export interface IDocStateChangeInfo extends IDocStateChangeParams {
|
|
18
18
|
isCompositionEnd?: boolean;
|
|
19
|
+
isSync?: boolean;
|
|
20
|
+
syncer?: string;
|
|
19
21
|
}
|
|
20
22
|
export declare class DocStateEmitService extends RxDisposable {
|
|
21
23
|
private readonly _docStateChangeParams$;
|
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}=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.replaceTextRanges(textRanges,isEditing,params.options)});const changeState={commandId:RichTextEditingMutationId,unitId,segmentId,trigger,noHistory,debounce,redoState:{actions,textRanges},undoState:{actions:undoActions,textRanges:prevTextRanges!=null?prevTextRanges:docRanges},isCompositionEnd};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(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"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet normal base-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"rxjs": ">=7.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@univerjs/core": "0.4.
|
|
53
|
-
"@univerjs/engine-render": "0.4.
|
|
52
|
+
"@univerjs/core": "0.4.2",
|
|
53
|
+
"@univerjs/engine-render": "0.4.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"rxjs": "^7.8.1",
|
|
57
57
|
"typescript": "^5.6.3",
|
|
58
58
|
"vite": "^5.4.8",
|
|
59
59
|
"vitest": "^2.1.2",
|
|
60
|
-
"@univerjs-infra/shared": "0.4.
|
|
60
|
+
"@univerjs-infra/shared": "0.4.2"
|
|
61
61
|
},
|
|
62
62
|
"univerSpace": {
|
|
63
63
|
".": {
|