@univerjs/docs 0.4.2-nightly.202411081606 → 0.4.2-nightly.202411091134

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 G=Object.defineProperty;var k=(o,i,e)=>i in o?G(o,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[i]=e;var d=(o,i,e)=>k(o,typeof i!="symbol"?i+"":i,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),T=require("@univerjs/engine-render"),p=require("rxjs"),x=require("@univerjs/docs"),b={id:"doc.operation.set-selections",type:c.CommandType.OPERATION,handler:()=>!0};var W=Object.defineProperty,J=Object.getOwnPropertyDescriptor,Y=(o,i,e,t)=>{for(var n=t>1?void 0:t?J(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&&W(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:T.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:S}=n,f=[...u,...g].filter(_=>_.startOffset!=null&&_.endOffset!=null).sort((_,I)=>_.startOffset>I.startOffset?1:_.startOffset<I.startOffset?-1:0);this._commandService.executeCommand(b.id,{unitId:s,subUnitId:r,segmentId:a,style:l,isEditing:S,ranges:f})}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=Y([j(0,c.ICommandService),j(1,c.IUniverInstanceService)],exports.DocSelectionManagerService);var q=Object.defineProperty,K=Object.getOwnPropertyDescriptor,H=(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&&q(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 T.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new T.DocumentViewModel(e)}};exports.DocSkeletonManagerService=H([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",F={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:S,isEditing:f=!0,isSync:_,syncer:I}=i,m=o.get(c.IUniverInstanceService),v=o.get(T.IRenderManagerService),R=o.get(P),h=m.getUniverDocInstance(e),O=($=v.getRenderById(e))==null?void 0:$.with(exports.DocSkeletonManagerService).getViewModel();if(h==null||O==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const D=o.get(exports.DocSelectionManagerService),y=(B=D.getDocRanges())!=null?B:[],L=!!h.getSnapshot().disabled;if(c.JSONX.isNoop(n)||n&&n.length===0||L)return{unitId:e,actions:[],textRanges:y};const N=c.JSONX.invertWithDoc(n,h.getSnapshot());h.apply(n),O.reset(h),!g&&s&&a!=null&&queueMicrotask(()=>{D.replaceDocRanges(s,{unitId:e,subUnitId:e},f,i.options)});const z={commandId:A,unitId:e,segmentId:t,trigger:a,noHistory:l,debounce:S,redoState:{actions:n,textRanges:s},undoState:{actions:N,textRanges:r!=null?r:y},isCompositionEnd:u,isSync:_,syncer:I};return R.emitStateChangeInfo(z),{unitId:e,actions:N,textRanges:y}}},Q={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}},Z="docs.config",ee={};var te=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,ie=(o,i,e,t)=>{for(var n=t>1?void 0:t?ne(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&&te(i,e,n),n},w=(o,i)=>(e,t)=>i(e,t,o);let C=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)}}))}};C=ie([w(0,c.ICommandService),w(1,c.Inject(exports.DocSelectionManagerService)),w(2,c.IUniverInstanceService)],C);var se=Object.defineProperty,re=Object.getOwnPropertyDescriptor,oe=(o,i,e,t)=>{for(var n=t>1?void 0:t?re(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&&se(i,e,n),n},X=(o,i)=>(e,t)=>i(e,t,o);const ce="DOCS_PLUGIN";var E;exports.UniverDocsPlugin=(E=class extends c.Plugin{constructor(i=ee,e,t){super(),this._config=i,this._injector=e,this._configService=t;const{...n}=this._config;this._configService.setConfig(Z,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[F,Q,b].forEach(i=>{this._injector.get(c.ICommandService).registerCommand(i)})}_initializeDependencies(){[[exports.DocSelectionManagerService],[P],[C]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(C)}},d(E,"pluginName",ce),E);exports.UniverDocsPlugin=oe([X(1,c.Inject(c.Injector)),X(2,c.IConfigService)],exports.UniverDocsPlugin);const ae=c.createInterceptorKey("CUSTOM_RANGE"),le=c.createInterceptorKey("CUSTOM_DECORATION"),M={CUSTOM_RANGE:ae,CUSTOM_DECORATION:le};var ue=Object.defineProperty,de=Object.getOwnPropertyDescriptor,ge=(o,i,e,t)=>{for(var n=t>1?void 0:t?de(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&&ue(i,e,n),n},_e=(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=ge([_e(1,c.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);function U(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 he(o,i,e){const{unitId:t,segmentId:n}=i,r=o.get(c.IUniverInstanceService).getUnit(t);if(!r)return!1;const a={id:x.RichTextEditingMutation.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=U(r,n);return a.params.actions=l.editOp(u.serialize(),g),a}function Se(o,i){var D;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:r,selection:a}=i,l=o.get(x.DocSelectionManagerService),u=o.get(c.IUniverInstanceService),g=a!=null?a:(D=l.getTextRanges({unitId:r,subUnitId:r}))==null?void 0:D[0],S=g==null?void 0:g.segmentId;if(!g)return!1;const f=u.getUnit(r,c.UniverInstanceType.UNIVER_DOC);if(!f)return!1;const _=f.getSelfOrHeaderFooterModel(g.segmentId).getBody();if(!_)return!1;const{startOffset:I,endOffset:m}=c.BuildTextUtils.selection.normalizeSelection(g),v=c.BuildTextUtils.customRange.add({range:{startOffset:I,endOffset:m,collapsed:I===m},rangeId:e,rangeType:t,segmentId:S,wholeEntity:n,properties:s,body:_});if(!v)return!1;const R=c.JSONX.getInstance(),h={id:x.RichTextEditingMutation.id,params:{unitId:r,actions:[],textRanges:v.selections},textX:v},O=U(f,S);return h.params.actions=R.editOp(v.serialize(),O),h}function fe(o,i){const{unitId:e,segmentId:t,insert:n}=i,r=o.get(c.IUniverInstanceService).getUnit(e);if(!r)return!1;const a={id:x.RichTextEditingMutation.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=U(r,t);return a.params.actions=l.editOp(u.serialize(),g),a.params.textRanges=u.selections,a}function Ie(o,i){var m,v,R,h;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=(m=i.selection)==null?void 0:m.segmentId,a=(v=s.getSelfOrHeaderFooterModel(r))==null?void 0:v.getBody();if(!a)return!1;const l=o.get(x.DocSelectionManagerService),u=(R=i.selection)!=null?R:l.getActiveTextRange();if(!u||!a)return!1;const g=(h=i.textRanges)!=null?h:[{startOffset:u.startOffset+t.dataStream.length,endOffset:u.startOffset+t.dataStream.length,collapsed:!0,segmentId:r}],S=c.BuildTextUtils.selection.replace({selection:u,body:t,doc:s});if(!S)return!1;const f={id:x.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:g,debounce:!0,segmentId:r},textX:S},_=c.JSONX.getInstance(),I=U(s,r);return f.params.actions=_.editOp(S.serialize(),I),f}exports.DOC_INTERCEPTOR_POINT=M;exports.DocStateEmitService=P;exports.RichTextEditingMutation=F;exports.SetTextSelectionsOperation=b;exports.addCustomRangeBySelectionFactory=Se;exports.addCustomRangeFactory=he;exports.deleteCustomRangeFactory=fe;exports.replaceSelectionFactory=Ie;
1
+ "use strict";var z=Object.defineProperty;var G=(o,s,e)=>s in o?z(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var d=(o,s,e)=>G(o,typeof s!="symbol"?s+"":s,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,s,e,t)=>{for(var n=t>1?void 0:t?W(s,e):s,i=o.length-1,r;i>=0;i--)(r=o[i])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&k(s,e,n),n},j=(o,s)=>(e,t)=>s(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,i){if(t==null)return;const{unitId:r,subUnitId:a}=t;this._refreshSelection$.next({unitId:r,subUnitId:a,docRanges:e,isEditing:n,options:i})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;const n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:i,subUnitId:r,segmentId:a,style:l,textRanges:u,rectRanges:g,isEditing:S}=n,f=[...u,...g].filter(_=>_.startOffset!=null&&_.endOffset!=null).sort((_,I)=>_.startOffset>I.startOffset?1:_.startOffset<I.startOffset?-1:0);this._commandService.executeCommand(b.id,{unitId:i,subUnitId:r,segmentId:a,style:l,isEditing:S,ranges:f})}dispose(){this._textSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_getTextRanges(e){var i;if(e==null)return;const{unitId:t,subUnitId:n=""}=e;return(i=this._textSelectionInfo.get(t))==null?void 0:i.get(n)}_refresh(e){const t=this._getTextRanges(e);if(t==null)return;const{textRanges:n,rectRanges:i}=t,r=[...n,...i],{unitId:a,subUnitId:l}=e;this._refreshSelection$.next({unitId:a,subUnitId:l,docRanges:r,isEditing:!1})}_replaceByParam(e){const{unitId:t,subUnitId:n,...i}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...i})}_addByParam(e){const{unitId:t,subUnitId:n,...i}=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,{...i})}};exports.DocSelectionManagerService=J([j(0,c.ICommandService),j(1,c.IUniverInstanceService)],exports.DocSelectionManagerService);var Y=Object.defineProperty,K=Object.getOwnPropertyDescriptor,q=(o,s,e,t)=>{for(var n=t>1?void 0:t?K(s,e):s,i=o.length-1,r;i>=0;i--)(r=o[i])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&Y(s,e,n),n},V=(o,s)=>(e,t)=>s(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(i=>{i&&i.getUnitId()===this._context.unitId&&this._update(i)})}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 E 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,s)=>{var $,B;const{unitId:e,segmentId:t="",actions:n,textRanges:i,prevTextRanges:r,trigger:a,noHistory:l,isCompositionEnd:u,noNeedSetTextRange:g,debounce:S,isEditing:f=!0,isSync:_,syncer:I}=s,m=o.get(c.IUniverInstanceService),v=o.get(C.IRenderManagerService),R=o.get(E),h=m.getUniverDocInstance(e),x=($=v.getRenderById(e))==null?void 0:$.with(exports.DocSkeletonManagerService).getViewModel();if(h==null||x==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const D=o.get(exports.DocSelectionManagerService),y=(B=D.getDocRanges())!=null?B:[],F=!!h.getSnapshot().disabled;if(c.JSONX.isNoop(n)||n&&n.length===0||F)return{unitId:e,actions:[],textRanges:y};const N=c.JSONX.invertWithDoc(n,h.getSnapshot());h.apply(n),x.reset(h),!g&&i&&a!=null&&queueMicrotask(()=>{D.replaceDocRanges(i,{unitId:e,subUnitId:e},f,s.options)});const L={commandId:A,unitId:e,segmentId:t,trigger:a,noHistory:l,debounce:S,redoState:{actions:n,textRanges:i},undoState:{actions:N,textRanges:r!=null?r:y},isCompositionEnd:u,isSync:_,syncer:I};return R.emitStateChangeInfo(L),{unitId:e,actions:N,textRanges:y}}},H={id:"doc.mutation.rename-doc",type:c.CommandType.MUTATION,handler:(o,s)=>{const t=o.get(c.IUniverInstanceService).getUnit(s.unitId,c.UniverInstanceType.UNIVER_DOC);return t?(t.setName(s.name),!0):!1}},Q="docs.config",Z={};var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(o,s,e,t)=>{for(var n=t>1?void 0:t?te(s,e):s,i=o.length-1,r;i>=0;i--)(r=o[i])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&ee(s,e,n),n},w=(o,s)=>(e,t)=>s(e,t,o);let T=class extends c.Disposable{constructor(o,s,e){super(),this._commandService=o,this._textSelectionManagerService=s,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(o,s){var r;const{startOffset:e,endOffset:t,collapsed:n}=s,i=(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(i!=null&&i.length){let a=e,l=t;return i.forEach(u=>{a=Math.min(u.startIndex,a),l=Math.max(u.endIndex+1,l)}),{...s,startOffset:a,endOffset:l,collapsed:a===l}}return s}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===b.id){const s=o.params,{unitId:e,ranges:t,isEditing:n}=s,i=this._univerInstanceService.getUnit(e);if(!i)return;const r=t.map(a=>this._transformCustomRange(i,a));r.some((a,l)=>t[l]!==a)&&this._textSelectionManagerService.replaceTextRanges(r,n)}}))}};T=ne([w(0,c.ICommandService),w(1,c.Inject(exports.DocSelectionManagerService)),w(2,c.IUniverInstanceService)],T);var se=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,re=(o,s,e,t)=>{for(var n=t>1?void 0:t?ie(s,e):s,i=o.length-1,r;i>=0;i--)(r=o[i])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&se(s,e,n),n},X=(o,s)=>(e,t)=>s(e,t,o);const oe="DOCS_PLUGIN";var P;exports.UniverDocsPlugin=(P=class extends c.Plugin{constructor(s=Z,e,t){super(),this._config=s,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(s=>{this._injector.get(c.ICommandService).registerCommand(s)})}_initializeDependencies(){[[exports.DocSelectionManagerService],[E],[T]].forEach(s=>this._injector.add(s))}onReady(){this._injector.get(T)}},d(P,"pluginName",oe),P);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,s,e,t)=>{for(var n=t>1?void 0:t?ue(s,e):s,i=o.length-1,r;i>=0;i--)(r=o[i])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&le(s,e,n),n},ge=(o,s)=>(e,t)=>s(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(),i=n.getDataModel().getUnitId();if(i===c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===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 i=this._interceptorsByName.get(n);return i.push(t),this._interceptorsByName.set(n,i.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 i;return this.fetchThroughInterceptors(M.CUSTOM_RANGE)(e.getCustomRangeRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customRanges:(i=e.getDataModel().getCustomRanges())!=null?i:[]})},getCustomDecoration:n=>{var i;return this.fetchThroughInterceptors(M.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(i=e.getDataModel().getCustomDecorations())!=null?i:[]})}})),t}};exports.DocInterceptorService=de([ge(1,c.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);function U(o,s=""){if(!s)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[s])!=null)return["headers",s,"body"];if((t==null?void 0:t[s])!=null)return["footers",s,"body"];throw new Error("Segment id not found in headers or footers")}function _e(o,s,e){const{unitId:t,segmentId:n}=s,r=o.get(c.IUniverInstanceService).getUnit(t);if(!r)return!1;const a={id:O.id,params:{unitId:s.unitId,actions:[],textRanges:void 0}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.add({...s,body:e});if(!u)return!1;const g=U(r,n);return a.params.actions=l.editOp(u.serialize(),g),a}function he(o,s){var D;const{rangeId:e,rangeType:t,wholeEntity:n,properties:i,unitId:r,selection:a}=s,l=o.get(exports.DocSelectionManagerService),u=o.get(c.IUniverInstanceService),g=a!=null?a:(D=l.getTextRanges({unitId:r,subUnitId:r}))==null?void 0:D[0],S=g==null?void 0:g.segmentId;if(!g)return!1;const f=u.getUnit(r,c.UniverInstanceType.UNIVER_DOC);if(!f)return!1;const _=f.getSelfOrHeaderFooterModel(g.segmentId).getBody();if(!_)return!1;const{startOffset:I,endOffset:m}=c.BuildTextUtils.selection.normalizeSelection(g),v=c.BuildTextUtils.customRange.add({range:{startOffset:I,endOffset:m,collapsed:I===m},rangeId:e,rangeType:t,segmentId:S,wholeEntity:n,properties:i,body:_});if(!v)return!1;const R=c.JSONX.getInstance(),h={id:O.id,params:{unitId:r,actions:[],textRanges:v.selections},textX:v},x=U(f,S);return h.params.actions=R.editOp(v.serialize(),x),h}function Se(o,s){const{unitId:e,segmentId:t,insert:n}=s,r=o.get(c.IUniverInstanceService).getUnit(e);if(!r)return!1;const a={id:O.id,params:{unitId:s.unitId,actions:[],textRanges:void 0,segmentId:t}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.delete(o,{documentDataModel:r,rangeId:s.rangeId,insert:n,segmentId:t});if(!u)return!1;const g=U(r,t);return a.params.actions=l.editOp(u.serialize(),g),a.params.textRanges=u.selections,a}function fe(o,s){var m,v,R,h;const{unitId:e,body:t,doc:n}=s;let i=n;if(i||(i=o.get(c.IUniverInstanceService).getUnit(e)),!i)return!1;const r=(m=s.selection)==null?void 0:m.segmentId,a=(v=i.getSelfOrHeaderFooterModel(r))==null?void 0:v.getBody();if(!a)return!1;const l=o.get(exports.DocSelectionManagerService),u=(R=s.selection)!=null?R:l.getActiveTextRange();if(!u||!a)return!1;const g=(h=s.textRanges)!=null?h:[{startOffset:u.startOffset+t.dataStream.length,endOffset:u.startOffset+t.dataStream.length,collapsed:!0,segmentId:r}],S=c.BuildTextUtils.selection.replace({selection:u,body:t,doc:i});if(!S)return!1;const f={id:O.id,params:{unitId:e,actions:[],textRanges:g,debounce:!0,segmentId:r},textX:S},_=c.JSONX.getInstance(),I=U(i,r);return f.params.actions=_.editOp(S.serialize(),I),f}exports.DOC_INTERCEPTOR_POINT=M;exports.DocStateEmitService=E;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,33 +1,32 @@
1
- var ie = Object.defineProperty;
2
- var re = (i, e, t) => e in i ? ie(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var u = (i, e, t) => re(i, typeof e != "symbol" ? e + "" : e, t);
4
- import { CommandType as j, RxDisposable as A, UniverInstanceType as w, ICommandService as L, IUniverInstanceService as p, Inject as $, LocaleService as oe, isInternalEditorID as ce, JSONX as R, Disposable as J, BuildTextUtils as O, Injector as ae, Plugin as le, IConfigService as ue, createInterceptorKey as Q, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as de, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as ge, DisposableCollection as P, toDisposable as _e, remove as he, composeInterceptors as fe } from "@univerjs/core";
5
- import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as Se, DocumentSkeleton as pe, DocumentViewModel as Ie, IRenderManagerService as me } from "@univerjs/engine-render";
6
- import { Subject as ve, BehaviorSubject as C, takeUntil as Z } from "rxjs";
7
- import { RichTextEditingMutation as y, DocSelectionManagerService as ee } from "@univerjs/docs";
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 j, RxDisposable as A, UniverInstanceType as y, ICommandService as L, 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 P, toDisposable as ge, remove as _e, composeInterceptors as he } from "@univerjs/core";
5
+ import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as fe, DocumentSkeleton as Se, DocumentViewModel as pe, IRenderManagerService as Ie } from "@univerjs/engine-render";
6
+ import { Subject as me, BehaviorSubject as D, takeUntil as Z } from "rxjs";
8
7
  const X = {
9
8
  id: "doc.operation.set-selections",
10
9
  type: j.OPERATION,
11
10
  handler: () => !0
12
11
  };
13
- var Re = Object.defineProperty, Oe = Object.getOwnPropertyDescriptor, xe = (i, e, t, n) => {
14
- for (var s = n > 1 ? void 0 : n ? Oe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
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--)
15
14
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
16
- return n && s && Re(e, t, s), s;
15
+ return n && s && ve(e, t, s), s;
17
16
  }, W = (i, e) => (t, n) => e(t, n, i);
18
- let D = class extends A {
17
+ let m = class extends A {
19
18
  constructor(e, t) {
20
19
  super();
21
20
  u(this, "_currentSelection", null);
22
21
  u(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
23
- u(this, "_textSelection$", new ve());
22
+ u(this, "_textSelection$", new me());
24
23
  u(this, "textSelection$", this._textSelection$.asObservable());
25
- u(this, "_refreshSelection$", new C(null));
24
+ u(this, "_refreshSelection$", new D(null));
26
25
  u(this, "refreshSelection$", this._refreshSelection$.asObservable());
27
26
  this._commandService = e, this._univerInstanceService = t, this._listenCurrentUnit();
28
27
  }
29
28
  _listenCurrentUnit() {
30
- this._univerInstanceService.getCurrentTypeOfUnit$(w.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((e) => {
29
+ this._univerInstanceService.getCurrentTypeOfUnit$(y.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((e) => {
31
30
  if (e == null)
32
31
  return;
33
32
  const t = e.getUnitId();
@@ -90,7 +89,7 @@ let D = class extends A {
90
89
  segmentId: "",
91
90
  segmentPage: -1,
92
91
  isEditing: t,
93
- style: Se
92
+ style: fe
94
93
  // mock style.
95
94
  });
96
95
  }
@@ -173,28 +172,28 @@ let D = class extends A {
173
172
  r.has(n) ? r.get(n).textRanges.push(...e.textRanges) : r.set(n, { ...s });
174
173
  }
175
174
  };
176
- D = xe([
175
+ m = Oe([
177
176
  W(0, L),
178
177
  W(1, p)
179
- ], D);
180
- var Me = Object.defineProperty, Ce = Object.getOwnPropertyDescriptor, De = (i, e, t, n) => {
178
+ ], m);
179
+ var xe = Object.defineProperty, Ce = Object.getOwnPropertyDescriptor, Me = (i, e, t, n) => {
181
180
  for (var s = n > 1 ? void 0 : n ? Ce(e, t) : e, r = i.length - 1, o; r >= 0; r--)
182
181
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
183
- return n && s && Me(e, t, s), s;
182
+ return n && s && xe(e, t, s), s;
184
183
  }, Y = (i, e) => (t, n) => e(t, n, i);
185
- let T = class extends A {
184
+ let b = class extends A {
186
185
  constructor(e, t, n) {
187
186
  super();
188
187
  u(this, "_skeleton");
189
188
  u(this, "_docViewModel");
190
- u(this, "_currentSkeleton$", new C(null));
189
+ u(this, "_currentSkeleton$", new D(null));
191
190
  u(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
192
191
  // CurrentSkeletonBefore for pre-triggered logic during registration
193
- u(this, "_currentSkeletonBefore$", new C(null));
192
+ u(this, "_currentSkeletonBefore$", new D(null));
194
193
  u(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
195
- u(this, "_currentViewModel$", new C(null));
194
+ u(this, "_currentViewModel$", new D(null));
196
195
  u(this, "currentViewModel$", this._currentViewModel$.asObservable());
197
- this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(w.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((s) => {
196
+ this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(y.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((s) => {
198
197
  s && s.getUnitId() === this._context.unitId && this._update(s);
199
198
  });
200
199
  }
@@ -215,25 +214,25 @@ let T = class extends A {
215
214
  const t = this._context.unitId;
216
215
  if (e.getBody() == null)
217
216
  return;
218
- this._docViewModel && ce(t) ? (this._docViewModel.reset(e), this._context.unit = e) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(e)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
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));
219
218
  const n = this._skeleton;
220
219
  n.calculate(), this._currentSkeletonBefore$.next(n), this._currentSkeleton$.next(n), this._currentViewModel$.next(this._docViewModel);
221
220
  }
222
221
  _buildSkeleton(e) {
223
- return pe.create(e, this._localeService);
222
+ return Se.create(e, this._localeService);
224
223
  }
225
224
  _buildDocViewModel(e) {
226
- return new Ie(e);
225
+ return new pe(e);
227
226
  }
228
227
  };
229
- T = De([
230
- Y(1, $(oe)),
228
+ b = Me([
229
+ Y(1, $(re)),
231
230
  Y(2, p)
232
- ], T);
233
- class te extends A {
231
+ ], b);
232
+ class ee extends A {
234
233
  constructor() {
235
234
  super();
236
- u(this, "_docStateChangeParams$", new C(null));
235
+ u(this, "_docStateChangeParams$", new D(null));
237
236
  u(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
238
237
  }
239
238
  emitStateChangeInfo(t) {
@@ -243,7 +242,7 @@ class te extends A {
243
242
  super.dispose(), this._docStateChangeParams$.complete();
244
243
  }
245
244
  }
246
- const K = "doc.mutation.rich-text-editing", Te = {
245
+ const K = "doc.mutation.rich-text-editing", T = {
247
246
  id: K,
248
247
  type: j.MUTATION,
249
248
  // eslint-disable-next-line max-lines-per-function
@@ -262,22 +261,22 @@ const K = "doc.mutation.rich-text-editing", Te = {
262
261
  debounce: h,
263
262
  isEditing: g = !0,
264
263
  isSync: f,
265
- syncer: m
266
- } = e, I = i.get(p), S = i.get(me), v = i.get(te), _ = I.getUniverDocInstance(t), x = (G = S.getRenderById(t)) == null ? void 0 : G.with(T).getViewModel();
267
- if (_ == null || x == null)
264
+ syncer: v
265
+ } = e, I = i.get(p), S = i.get(Ie), R = i.get(ee), _ = I.getUniverDocInstance(t), C = (G = S.getRenderById(t)) == null ? void 0 : G.with(b).getViewModel();
266
+ if (_ == null || C == null)
268
267
  throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
269
- const M = i.get(D), E = (F = M.getDocRanges()) != null ? F : [], ne = !!_.getSnapshot().disabled;
270
- if (R.isNoop(s) || s && s.length === 0 || ne)
268
+ const M = i.get(m), E = (F = M.getDocRanges()) != null ? F : [], te = !!_.getSnapshot().disabled;
269
+ if (O.isNoop(s) || s && s.length === 0 || te)
271
270
  return {
272
271
  unitId: t,
273
272
  actions: [],
274
273
  textRanges: E
275
274
  };
276
- const z = R.invertWithDoc(s, _.getSnapshot());
277
- _.apply(s), x.reset(_), !d && r && c != null && queueMicrotask(() => {
275
+ const z = O.invertWithDoc(s, _.getSnapshot());
276
+ _.apply(s), C.reset(_), !d && r && c != null && queueMicrotask(() => {
278
277
  M.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
279
278
  });
280
- const se = {
279
+ const ne = {
281
280
  commandId: K,
282
281
  unitId: t,
283
282
  segmentId: n,
@@ -294,34 +293,34 @@ const K = "doc.mutation.rich-text-editing", Te = {
294
293
  },
295
294
  isCompositionEnd: l,
296
295
  isSync: f,
297
- syncer: m
296
+ syncer: v
298
297
  };
299
- return v.emitStateChangeInfo(se), {
298
+ return R.emitStateChangeInfo(ne), {
300
299
  unitId: t,
301
300
  actions: z,
302
301
  textRanges: E
303
302
  };
304
303
  }
305
- }, be = {
304
+ }, De = {
306
305
  id: "doc.mutation.rename-doc",
307
306
  type: j.MUTATION,
308
307
  handler: (i, e) => {
309
- const n = i.get(p).getUnit(e.unitId, w.UNIVER_DOC);
308
+ const n = i.get(p).getUnit(e.unitId, y.UNIVER_DOC);
310
309
  return n ? (n.setName(e.name), !0) : !1;
311
310
  }
312
- }, we = "docs.config", $e = {};
313
- var ye = Object.defineProperty, Ue = Object.getOwnPropertyDescriptor, Ee = (i, e, t, n) => {
314
- for (var s = n > 1 ? void 0 : n ? Ue(e, t) : e, r = i.length - 1, o; r >= 0; r--)
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--)
315
314
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
316
- return n && s && ye(e, t, s), s;
315
+ return n && s && we(e, t, s), s;
317
316
  }, N = (i, e) => (t, n) => e(t, n, i);
318
- let b = class extends J {
317
+ let w = class extends J {
319
318
  constructor(i, e, t) {
320
319
  super(), this._commandService = i, this._textSelectionManagerService = e, this._univerInstanceService = t, this._initSelectionChange();
321
320
  }
322
321
  _transformCustomRange(i, e) {
323
322
  var o;
324
- 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 : O.range.isIntersects(t, n - 1, c.startIndex, c.endIndex));
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));
325
324
  if (r != null && r.length) {
326
325
  let c = t, a = n;
327
326
  return r.forEach((l) => {
@@ -347,32 +346,32 @@ let b = class extends J {
347
346
  }));
348
347
  }
349
348
  };
350
- b = Ee([
349
+ w = $e([
351
350
  N(0, L),
352
- N(1, $(D)),
351
+ N(1, $(m)),
353
352
  N(2, p)
354
- ], b);
355
- var Pe = Object.defineProperty, Ne = Object.getOwnPropertyDescriptor, Ve = (i, e, t, n) => {
356
- for (var s = n > 1 ? void 0 : n ? Ne(e, t) : e, r = i.length - 1, o; r >= 0; r--)
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--)
357
356
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
358
- return n && s && Pe(e, t, s), s;
357
+ return n && s && Ue(e, t, s), s;
359
358
  }, H = (i, e) => (t, n) => e(t, n, i);
360
- const Be = "DOCS_PLUGIN";
359
+ const Ne = "DOCS_PLUGIN";
361
360
  var B;
362
- let k = (B = class extends le {
361
+ let k = (B = class extends ae {
363
362
  // static override type = UniverInstanceType.UNIVER_DOC;
364
- constructor(i = $e, e, t) {
363
+ constructor(i = be, e, t) {
365
364
  super(), this._config = i, this._injector = e, this._configService = t;
366
365
  const { ...n } = this._config;
367
- this._configService.setConfig(we, n);
366
+ this._configService.setConfig(Te, n);
368
367
  }
369
368
  onStarting() {
370
369
  this._initializeDependencies(), this._initializeCommands();
371
370
  }
372
371
  _initializeCommands() {
373
372
  [
374
- Te,
375
- be,
373
+ T,
374
+ De,
376
375
  X
377
376
  ].forEach((i) => {
378
377
  this._injector.get(L).registerCommand(i);
@@ -380,35 +379,35 @@ let k = (B = class extends le {
380
379
  }
381
380
  _initializeDependencies() {
382
381
  [
383
- [D],
384
- [te],
385
- [b]
382
+ [m],
383
+ [ee],
384
+ [w]
386
385
  ].forEach((i) => this._injector.add(i));
387
386
  }
388
387
  onReady() {
389
- this._injector.get(b);
388
+ this._injector.get(w);
390
389
  }
391
- }, u(B, "pluginName", Be), B);
392
- k = Ve([
393
- H(1, $(ae)),
394
- H(2, ue)
390
+ }, u(B, "pluginName", Ne), B);
391
+ k = Pe([
392
+ H(1, $(ce)),
393
+ H(2, le)
395
394
  ], k);
396
- const je = Q("CUSTOM_RANGE"), Ae = Q("CUSTOM_DECORATION"), V = {
397
- CUSTOM_RANGE: je,
398
- CUSTOM_DECORATION: Ae
395
+ const Ve = Q("CUSTOM_RANGE"), Be = Q("CUSTOM_DECORATION"), V = {
396
+ CUSTOM_RANGE: Ve,
397
+ CUSTOM_DECORATION: Be
399
398
  };
400
- var Le = Object.defineProperty, Xe = Object.getOwnPropertyDescriptor, ze = (i, e, t, n) => {
401
- for (var s = n > 1 ? void 0 : n ? Xe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
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--)
402
401
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
403
- return n && s && Le(e, t, s), s;
404
- }, Ge = (i, e) => (t, n) => e(t, n, i);
402
+ return n && s && je(e, t, s), s;
403
+ }, Xe = (i, e) => (t, n) => e(t, n, i);
405
404
  let q = class extends J {
406
405
  constructor(e, t) {
407
406
  super();
408
407
  u(this, "_interceptorsByName", /* @__PURE__ */ new Map());
409
408
  this._context = e, this._docSkeletonManagerService = t;
410
409
  const n = this._docSkeletonManagerService.getViewModel(), s = n.getDataModel().getUnitId();
411
- if (s === de || s === ge)
410
+ if (s === ue || s === de)
412
411
  return;
413
412
  this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(V.CUSTOM_RANGE, {
414
413
  priority: -1,
@@ -431,11 +430,11 @@ let q = class extends J {
431
430
  var c, a;
432
431
  return ((c = o.priority) != null ? c : 0) - ((a = r.priority) != null ? a : 0);
433
432
  })
434
- ), this.disposeWithMe(_e(() => he(this._interceptorsByName.get(n), t)));
433
+ ), this.disposeWithMe(ge(() => _e(this._interceptorsByName.get(n), t)));
435
434
  }
436
435
  fetchThroughInterceptors(e) {
437
436
  const t = e, n = this._interceptorsByName.get(t);
438
- return fe(n || []);
437
+ return he(n || []);
439
438
  }
440
439
  interceptDocumentViewModel(e) {
441
440
  const t = new P();
@@ -465,8 +464,8 @@ let q = class extends J {
465
464
  })), t;
466
465
  }
467
466
  };
468
- q = ze([
469
- Ge(1, $(T))
467
+ q = Le([
468
+ Xe(1, $(b))
470
469
  ], q);
471
470
  function U(i, e = "") {
472
471
  if (!e)
@@ -480,36 +479,36 @@ function U(i, e = "") {
480
479
  return ["footers", e, "body"];
481
480
  throw new Error("Segment id not found in headers or footers");
482
481
  }
483
- function ke(i, e, t) {
482
+ function Ye(i, e, t) {
484
483
  const { unitId: n, segmentId: s } = e, o = i.get(p).getUnit(n);
485
484
  if (!o)
486
485
  return !1;
487
486
  const c = {
488
- id: y.id,
487
+ id: T.id,
489
488
  params: {
490
489
  unitId: e.unitId,
491
490
  actions: [],
492
491
  textRanges: void 0
493
492
  }
494
- }, a = R.getInstance(), l = O.customRange.add({ ...e, body: t });
493
+ }, a = O.getInstance(), l = x.customRange.add({ ...e, body: t });
495
494
  if (!l)
496
495
  return !1;
497
496
  const d = U(o, s);
498
497
  return c.params.actions = a.editOp(l.serialize(), d), c;
499
498
  }
500
- function qe(i, e) {
499
+ function Ke(i, e) {
501
500
  var M;
502
- const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selection: c } = e, a = i.get(ee), l = i.get(p), d = c != null ? c : (M = a.getTextRanges({ unitId: o, subUnitId: o })) == null ? void 0 : M[0], h = d == null ? void 0 : d.segmentId;
501
+ const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selection: c } = e, a = i.get(m), l = i.get(p), d = c != null ? c : (M = a.getTextRanges({ unitId: o, subUnitId: o })) == null ? void 0 : M[0], h = d == null ? void 0 : d.segmentId;
503
502
  if (!d)
504
503
  return !1;
505
- const g = l.getUnit(o, w.UNIVER_DOC);
504
+ const g = l.getUnit(o, y.UNIVER_DOC);
506
505
  if (!g)
507
506
  return !1;
508
507
  const f = g.getSelfOrHeaderFooterModel(d.segmentId).getBody();
509
508
  if (!f)
510
509
  return !1;
511
- const { startOffset: m, endOffset: I } = O.selection.normalizeSelection(d), S = O.customRange.add({
512
- range: { startOffset: m, endOffset: I, collapsed: m === I },
510
+ const { startOffset: v, endOffset: I } = x.selection.normalizeSelection(d), S = x.customRange.add({
511
+ range: { startOffset: v, endOffset: I, collapsed: v === I },
513
512
  rangeId: t,
514
513
  rangeType: n,
515
514
  segmentId: h,
@@ -519,30 +518,30 @@ function qe(i, e) {
519
518
  });
520
519
  if (!S)
521
520
  return !1;
522
- const v = R.getInstance(), _ = {
523
- id: y.id,
521
+ const R = O.getInstance(), _ = {
522
+ id: T.id,
524
523
  params: {
525
524
  unitId: o,
526
525
  actions: [],
527
526
  textRanges: S.selections
528
527
  },
529
528
  textX: S
530
- }, x = U(g, h);
531
- return _.params.actions = v.editOp(S.serialize(), x), _;
529
+ }, C = U(g, h);
530
+ return _.params.actions = R.editOp(S.serialize(), C), _;
532
531
  }
533
- function Je(i, e) {
532
+ function He(i, e) {
534
533
  const { unitId: t, segmentId: n, insert: s } = e, o = i.get(p).getUnit(t);
535
534
  if (!o)
536
535
  return !1;
537
536
  const c = {
538
- id: y.id,
537
+ id: T.id,
539
538
  params: {
540
539
  unitId: e.unitId,
541
540
  actions: [],
542
541
  textRanges: void 0,
543
542
  segmentId: n
544
543
  }
545
- }, a = R.getInstance(), l = O.customRange.delete(i, {
544
+ }, a = O.getInstance(), l = x.customRange.delete(i, {
546
545
  documentDataModel: o,
547
546
  rangeId: e.rangeId,
548
547
  insert: s,
@@ -553,15 +552,15 @@ function Je(i, e) {
553
552
  const d = U(o, n);
554
553
  return c.params.actions = a.editOp(l.serialize(), d), c.params.textRanges = l.selections, c;
555
554
  }
556
- function Qe(i, e) {
557
- var I, S, v, _;
555
+ function ke(i, e) {
556
+ var I, S, R, _;
558
557
  const { unitId: t, body: n, doc: s } = e;
559
558
  let r = s;
560
559
  if (r || (r = i.get(p).getUnit(t)), !r)
561
560
  return !1;
562
561
  const o = (I = e.selection) == null ? void 0 : I.segmentId, c = (S = r.getSelfOrHeaderFooterModel(o)) == null ? void 0 : S.getBody();
563
562
  if (!c) return !1;
564
- const a = i.get(ee), l = (v = e.selection) != null ? v : a.getActiveTextRange();
563
+ const a = i.get(m), l = (R = e.selection) != null ? R : a.getActiveTextRange();
565
564
  if (!l || !c)
566
565
  return !1;
567
566
  const d = (_ = e.textRanges) != null ? _ : [{
@@ -569,7 +568,7 @@ function Qe(i, e) {
569
568
  endOffset: l.startOffset + n.dataStream.length,
570
569
  collapsed: !0,
571
570
  segmentId: o
572
- }], h = O.selection.replace({
571
+ }], h = x.selection.replace({
573
572
  selection: l,
574
573
  body: n,
575
574
  doc: r
@@ -577,7 +576,7 @@ function Qe(i, e) {
577
576
  if (!h)
578
577
  return !1;
579
578
  const g = {
580
- id: y.id,
579
+ id: T.id,
581
580
  params: {
582
581
  unitId: t,
583
582
  actions: [],
@@ -586,20 +585,20 @@ function Qe(i, e) {
586
585
  segmentId: o
587
586
  },
588
587
  textX: h
589
- }, f = R.getInstance(), m = U(r, o);
590
- return g.params.actions = f.editOp(h.serialize(), m), g;
588
+ }, f = O.getInstance(), v = U(r, o);
589
+ return g.params.actions = f.editOp(h.serialize(), v), g;
591
590
  }
592
591
  export {
593
592
  V as DOC_INTERCEPTOR_POINT,
594
593
  q as DocInterceptorService,
595
- D as DocSelectionManagerService,
596
- T as DocSkeletonManagerService,
597
- te as DocStateEmitService,
598
- Te as RichTextEditingMutation,
594
+ m as DocSelectionManagerService,
595
+ b as DocSkeletonManagerService,
596
+ ee as DocStateEmitService,
597
+ T as RichTextEditingMutation,
599
598
  X as SetTextSelectionsOperation,
600
599
  k as UniverDocsPlugin,
601
- qe as addCustomRangeBySelectionFactory,
602
- ke as addCustomRangeFactory,
603
- Je as deleteCustomRangeFactory,
604
- Qe as replaceSelectionFactory
600
+ Ke as addCustomRangeBySelectionFactory,
601
+ Ye as addCustomRangeFactory,
602
+ He as deleteCustomRangeFactory,
603
+ ke as replaceSelectionFactory
605
604
  };
@@ -1,5 +1,5 @@
1
1
  import { CustomRangeType, DocumentDataModel, IAccessor, IAddCustomRangeTextXParam, IDocumentBody, IMutationInfo, ITextRangeParam, Nullable, TextX } from '@univerjs/core';
2
- import { IRichTextEditingMutationParams } from '@univerjs/docs';
2
+ import { IRichTextEditingMutationParams } from '../commands/mutations/core-editing.mutation';
3
3
  interface IAddCustomRangeParam extends IAddCustomRangeTextXParam {
4
4
  unitId: string;
5
5
  }
@@ -1,6 +1,6 @@
1
1
  import { DocumentDataModel, IAccessor, IDocumentBody, IMutationInfo, ITextRangeParam, TextX } from '@univerjs/core';
2
- import { IRichTextEditingMutationParams } from '@univerjs/docs';
3
2
  import { ITextRangeWithStyle } from '@univerjs/engine-render';
3
+ import { IRichTextEditingMutationParams } from '../commands/mutations/core-editing.mutation';
4
4
  export interface IReplaceSelectionFactoryParams {
5
5
  unitId: string;
6
6
  /**
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@univerjs/docs"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l.UniverDocs={},l.UniverCore,l.UniverEngineRender,l.rxjs,l.UniverDocs))})(this,function(l,r,v,R,D){"use strict";var Ie=Object.defineProperty;var ve=(l,r,v)=>r in l?Ie(l,r,{enumerable:!0,configurable:!0,writable:!0,value:v}):l[r]=v;var g=(l,r,v)=>ve(l,typeof r!="symbol"?r+"":r,v);var P;const x={id:"doc.operation.set-selections",type:r.CommandType.OPERATION,handler:()=>!0};var z=Object.defineProperty,G=Object.getOwnPropertyDescriptor,k=(c,i,e,t)=>{for(var n=t>1?void 0:t?G(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&&z(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:h,isEditing:S}=n,I=[...d,...h].filter(_=>_.startOffset!=null&&_.endOffset!=null).sort((_,p)=>_.startOffset>p.startOffset?1:_.startOffset<p.startOffset?-1:0);this._commandService.executeCommand(x.id,{unitId:s,subUnitId:o,segmentId:a,style:u,isEditing:S,ranges:I})}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=k([$(0,r.ICommandService),$(1,r.IUniverInstanceService)],l.DocSelectionManagerService);var W=Object.defineProperty,J=Object.getOwnPropertyDescriptor,Y=(c,i,e,t)=>{for(var n=t>1?void 0:t?J(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&&W(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=Y([B(1,r.Inject(r.LocaleService)),B(2,r.IUniverInstanceService)],l.DocSkeletonManagerService);class E 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",V={id:j,type:r.CommandType.MUTATION,handler:(c,i)=>{var F,L;const{unitId:e,segmentId:t="",actions:n,textRanges:s,prevTextRanges:o,trigger:a,noHistory:u,isCompositionEnd:d,noNeedSetTextRange:h,debounce:S,isEditing:I=!0,isSync:_,syncer:p}=i,O=c.get(r.IUniverInstanceService),m=c.get(v.IRenderManagerService),M=c.get(E),f=O.getUniverDocInstance(e),T=(F=m.getRenderById(e))==null?void 0:F.with(l.DocSkeletonManagerService).getViewModel();if(f==null||T==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const C=c.get(l.DocSelectionManagerService),N=(L=C.getDocRanges())!=null?L:[],fe=!!f.getSnapshot().disabled;if(r.JSONX.isNoop(n)||n&&n.length===0||fe)return{unitId:e,actions:[],textRanges:N};const X=r.JSONX.invertWithDoc(n,f.getSnapshot());f.apply(n),T.reset(f),!h&&s&&a!=null&&queueMicrotask(()=>{C.replaceDocRanges(s,{unitId:e,subUnitId:e},I,i.options)});const Se={commandId:j,unitId:e,segmentId:t,trigger:a,noHistory:u,debounce:S,redoState:{actions:n,textRanges:s},undoState:{actions:X,textRanges:o!=null?o:N},isCompositionEnd:d,isSync:_,syncer:p};return M.emitStateChangeInfo(Se),{unitId:e,actions:X,textRanges:N}}},q={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",H={};var Q=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,ee=(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&&Q(i,e,n),n},w=(c,i)=>(e,t)=>i(e,t,c);let U=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===x.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)}}))}};U=ee([w(0,r.ICommandService),w(1,r.Inject(l.DocSelectionManagerService)),w(2,r.IUniverInstanceService)],U);var te=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,ie=(c,i,e,t)=>{for(var n=t>1?void 0:t?ne(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&&te(i,e,n),n},A=(c,i)=>(e,t)=>i(e,t,c);const se="DOCS_PLUGIN";l.UniverDocsPlugin=(P=class extends r.Plugin{constructor(i=H,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(){[V,q,x].forEach(i=>{this._injector.get(r.ICommandService).registerCommand(i)})}_initializeDependencies(){[[l.DocSelectionManagerService],[E],[U]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(U)}},g(P,"pluginName",se),P),l.UniverDocsPlugin=ie([A(1,r.Inject(r.Injector)),A(2,r.IConfigService)],l.UniverDocsPlugin);const re=r.createInterceptorKey("CUSTOM_RANGE"),oe=r.createInterceptorKey("CUSTOM_DECORATION"),b={CUSTOM_RANGE:re,CUSTOM_DECORATION:oe};var ce=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,le=(c,i,e,t)=>{for(var n=t>1?void 0:t?ae(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&&ce(i,e,n),n},ue=(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(b.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(b.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(b.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(s=e.getDataModel().getCustomDecorations())!=null?s:[]})}})),t}},l.DocInterceptorService=le([ue(1,r.Inject(l.DocSkeletonManagerService))],l.DocInterceptorService);function y(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 de(c,i,e){const{unitId:t,segmentId:n}=i,o=c.get(r.IUniverInstanceService).getUnit(t);if(!o)return!1;const a={id:D.RichTextEditingMutation.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 h=y(o,n);return a.params.actions=u.editOp(d.serialize(),h),a}function ge(c,i){var C;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:o,selection:a}=i,u=c.get(D.DocSelectionManagerService),d=c.get(r.IUniverInstanceService),h=a!=null?a:(C=u.getTextRanges({unitId:o,subUnitId:o}))==null?void 0:C[0],S=h==null?void 0:h.segmentId;if(!h)return!1;const I=d.getUnit(o,r.UniverInstanceType.UNIVER_DOC);if(!I)return!1;const _=I.getSelfOrHeaderFooterModel(h.segmentId).getBody();if(!_)return!1;const{startOffset:p,endOffset:O}=r.BuildTextUtils.selection.normalizeSelection(h),m=r.BuildTextUtils.customRange.add({range:{startOffset:p,endOffset:O,collapsed:p===O},rangeId:e,rangeType:t,segmentId:S,wholeEntity:n,properties:s,body:_});if(!m)return!1;const M=r.JSONX.getInstance(),f={id:D.RichTextEditingMutation.id,params:{unitId:o,actions:[],textRanges:m.selections},textX:m},T=y(I,S);return f.params.actions=M.editOp(m.serialize(),T),f}function he(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.RichTextEditingMutation.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 h=y(o,t);return a.params.actions=u.editOp(d.serialize(),h),a.params.textRanges=d.selections,a}function _e(c,i){var O,m,M,f;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=(O=i.selection)==null?void 0:O.segmentId,a=(m=s.getSelfOrHeaderFooterModel(o))==null?void 0:m.getBody();if(!a)return!1;const u=c.get(D.DocSelectionManagerService),d=(M=i.selection)!=null?M:u.getActiveTextRange();if(!d||!a)return!1;const h=(f=i.textRanges)!=null?f:[{startOffset:d.startOffset+t.dataStream.length,endOffset:d.startOffset+t.dataStream.length,collapsed:!0,segmentId:o}],S=r.BuildTextUtils.selection.replace({selection:d,body:t,doc:s});if(!S)return!1;const I={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:h,debounce:!0,segmentId:o},textX:S},_=r.JSONX.getInstance(),p=y(s,o);return I.params.actions=_.editOp(S.serialize(),p),I}l.DOC_INTERCEPTOR_POINT=b,l.DocStateEmitService=E,l.RichTextEditingMutation=V,l.SetTextSelectionsOperation=x,l.addCustomRangeBySelectionFactory=ge,l.addCustomRangeFactory=de,l.deleteCustomRangeFactory=he,l.replaceSelectionFactory=_e,Object.defineProperty(l,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 x={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:S}=n,I=[...d,..._].filter(f=>f.startOffset!=null&&f.endOffset!=null).sort((f,p)=>f.startOffset>p.startOffset?1:f.startOffset<p.startOffset?-1:0);this._commandService.executeCommand(x.id,{unitId:s,subUnitId:o,segmentId:a,style:u,isEditing:S,ranges:I})}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 w 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:S,isEditing:I=!0,isSync:f,syncer:p}=i,O=c.get(r.IUniverInstanceService),m=c.get(v.IRenderManagerService),M=c.get(w),h=O.getUniverDocInstance(e),C=(X=m.getRenderById(e))==null?void 0:X.with(l.DocSkeletonManagerService).getViewModel();if(h==null||C==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const T=c.get(l.DocSelectionManagerService),N=(F=T.getDocRanges())!=null?F:[],fe=!!h.getSnapshot().disabled;if(r.JSONX.isNoop(n)||n&&n.length===0||fe)return{unitId:e,actions:[],textRanges:N};const A=r.JSONX.invertWithDoc(n,h.getSnapshot());h.apply(n),C.reset(h),!_&&s&&a!=null&&queueMicrotask(()=>{T.replaceDocRanges(s,{unitId:e,subUnitId:e},I,i.options)});const he={commandId:j,unitId:e,segmentId:t,trigger:a,noHistory:u,debounce:S,redoState:{actions:n,textRanges:s},undoState:{actions:A,textRanges:o!=null?o:N},isCompositionEnd:d,isSync:f,syncer:p};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},P=(c,i)=>(e,t)=>i(e,t,c);let U=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===x.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)}}))}};U=Z([P(0,r.ICommandService),P(1,r.Inject(l.DocSelectionManagerService)),P(2,r.IUniverInstanceService)],U);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,x].forEach(i=>{this._injector.get(r.ICommandService).registerCommand(i)})}_initializeDependencies(){[[l.DocSelectionManagerService],[w],[U]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(U)}},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"),b={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(b.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(b.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(b.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 y(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 _=y(o,n);return a.params.actions=u.editOp(d.serialize(),_),a}function de(c,i){var T;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:(T=u.getTextRanges({unitId:o,subUnitId:o}))==null?void 0:T[0],S=_==null?void 0:_.segmentId;if(!_)return!1;const I=d.getUnit(o,r.UniverInstanceType.UNIVER_DOC);if(!I)return!1;const f=I.getSelfOrHeaderFooterModel(_.segmentId).getBody();if(!f)return!1;const{startOffset:p,endOffset:O}=r.BuildTextUtils.selection.normalizeSelection(_),m=r.BuildTextUtils.customRange.add({range:{startOffset:p,endOffset:O,collapsed:p===O},rangeId:e,rangeType:t,segmentId:S,wholeEntity:n,properties:s,body:f});if(!m)return!1;const M=r.JSONX.getInstance(),h={id:D.id,params:{unitId:o,actions:[],textRanges:m.selections},textX:m},C=y(I,S);return h.params.actions=M.editOp(m.serialize(),C),h}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 _=y(o,t);return a.params.actions=u.editOp(d.serialize(),_),a.params.textRanges=d.selections,a}function _e(c,i){var O,m,M,h;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=(O=i.selection)==null?void 0:O.segmentId,a=(m=s.getSelfOrHeaderFooterModel(o))==null?void 0:m.getBody();if(!a)return!1;const u=c.get(l.DocSelectionManagerService),d=(M=i.selection)!=null?M:u.getActiveTextRange();if(!d||!a)return!1;const _=(h=i.textRanges)!=null?h:[{startOffset:d.startOffset+t.dataStream.length,endOffset:d.startOffset+t.dataStream.length,collapsed:!0,segmentId:o}],S=r.BuildTextUtils.selection.replace({selection:d,body:t,doc:s});if(!S)return!1;const I={id:D.id,params:{unitId:e,actions:[],textRanges:_,debounce:!0,segmentId:o},textX:S},f=r.JSONX.getInstance(),p=y(s,o);return I.params.actions=f.editOp(S.serialize(),p),I}l.DOC_INTERCEPTOR_POINT=b,l.DocStateEmitService=w,l.RichTextEditingMutation=D,l.SetTextSelectionsOperation=x,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-nightly.202411081606",
3
+ "version": "0.4.2-nightly.202411091134",
4
4
  "private": false,
5
5
  "description": "UniverSheet normal base-docs",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -49,8 +49,8 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@vitejs/plugin-react": "4.3.3",
52
- "@univerjs/core": "0.4.2-nightly.202411081606",
53
- "@univerjs/engine-render": "0.4.2-nightly.202411081606"
52
+ "@univerjs/engine-render": "0.4.2-nightly.202411091134",
53
+ "@univerjs/core": "0.4.2-nightly.202411091134"
54
54
  },
55
55
  "devDependencies": {
56
56
  "rxjs": "^7.8.1",