@univerjs/docs 0.5.1 → 0.5.2-nightly.202412291605

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"),D=require("@univerjs/engine-render"),v=require("rxjs"),C={id:"doc.operation.set-selections",type:c.CommandType.OPERATION,handler:()=>!0};var z=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(o,i,e,t)=>{for(var n=t>1?void 0:t?W(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&z(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 v.Subject);d(this,"textSelection$",this._textSelection$.asObservable());d(this,"_refreshSelection$",new v.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(v.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:D.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:_}=n,f=[...u,...g].filter(h=>h.startOffset!=null&&h.endOffset!=null).sort((h,S)=>h.startOffset>S.startOffset?1:h.startOffset<S.startOffset?-1:0);this._commandService.executeCommand(C.id,{unitId:s,subUnitId:r,segmentId:a,style:l,isEditing:_,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=J([j(0,c.ICommandService),j(1,c.IUniverInstanceService)],exports.DocSelectionManagerService);var Y=Object.defineProperty,K=Object.getOwnPropertyDescriptor,q=(o,i,e,t)=>{for(var n=t>1?void 0:t?K(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&Y(i,e,n),n},V=(o,i)=>(e,t)=>i(e,t,o);exports.DocSkeletonManagerService=class extends c.RxDisposable{constructor(e,t,n){super();d(this,"_skeleton");d(this,"_docViewModel");d(this,"_currentSkeleton$",new v.BehaviorSubject(null));d(this,"currentSkeleton$",this._currentSkeleton$.asObservable());d(this,"_currentSkeletonBefore$",new v.BehaviorSubject(null));d(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());d(this,"_currentViewModel$",new v.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(v.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 D.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new D.DocumentViewModel(e)}};exports.DocSkeletonManagerService=q([V(1,c.Inject(c.LocaleService)),V(2,c.IUniverInstanceService)],exports.DocSkeletonManagerService);class y extends c.RxDisposable{constructor(){super();d(this,"_docStateChangeParams$",new v.BehaviorSubject(null));d(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const A="doc.mutation.rich-text-editing",O={id:A,type:c.CommandType.MUTATION,handler:(o,i)=>{var $,B;const{unitId:e,segmentId:t="",actions:n,textRanges:s,prevTextRanges:r,trigger:a,noHistory:l,isCompositionEnd:u,noNeedSetTextRange:g,debounce:_,isEditing:f=!0,isSync:h,syncer:S}=i,m=o.get(c.IUniverInstanceService),p=o.get(D.IRenderManagerService),R=o.get(y),I=m.getUniverDocInstance(e),P=($=p.getRenderById(e))==null?void 0:$.with(exports.DocSkeletonManagerService).getViewModel();if(I==null||P==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const E=o.get(exports.DocSelectionManagerService),T=(B=E.getDocRanges())!=null?B:[],F=!!I.getSnapshot().disabled;if(c.JSONX.isNoop(n)||n&&n.length===0||F)return{unitId:e,actions:[],textRanges:T};const N=c.JSONX.invertWithDoc(n,I.getSnapshot());I.apply(n),P.reset(I),!g&&s&&a!=null&&queueMicrotask(()=>{E.replaceDocRanges(s,{unitId:e,subUnitId:e},f,i.options)});const L={commandId:A,unitId:e,segmentId:t,trigger:a,noHistory:l,debounce:_,redoState:{actions:n,textRanges:s},undoState:{actions:N,textRanges:r!=null?r:T},isCompositionEnd:u,isSync:h,syncer:S};return R.emitStateChangeInfo(L),{unitId:e,actions:N,textRanges:T}}},H={id:"doc.mutation.rename-doc",type:c.CommandType.MUTATION,handler:(o,i)=>{const t=o.get(c.IUniverInstanceService).getUnit(i.unitId,c.UniverInstanceType.UNIVER_DOC);return t?(t.setName(i.name),!0):!1}},Q="docs.config",Z={};var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(o,i,e,t)=>{for(var n=t>1?void 0:t?te(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ee(i,e,n),n},b=(o,i)=>(e,t)=>i(e,t,o);let M=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===C.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)}}))}};M=ne([b(0,c.ICommandService),b(1,c.Inject(exports.DocSelectionManagerService)),b(2,c.IUniverInstanceService)],M);var ie=Object.defineProperty,se=Object.getOwnPropertyDescriptor,re=(o,i,e,t)=>{for(var n=t>1?void 0:t?se(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ie(i,e,n),n},X=(o,i)=>(e,t)=>i(e,t,o);const oe="DOCS_PLUGIN";var U;exports.UniverDocsPlugin=(U=class extends c.Plugin{constructor(i=Z,e,t){super(),this._config=i,this._injector=e,this._configService=t;const{...n}=this._config;this._configService.setConfig(Q,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[O,H,C].forEach(i=>{this._injector.get(c.ICommandService).registerCommand(i)})}_initializeDependencies(){[[exports.DocSelectionManagerService],[y],[M]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(M)}},d(U,"pluginName",oe),U);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"),x={CUSTOM_RANGE:ce,CUSTOM_DECORATION:ae};var le=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,de=(o,i,e,t)=>{for(var n=t>1?void 0:t?ue(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&le(i,e,n),n},ge=(o,i)=>(e,t)=>i(e,t,o);exports.DocInterceptorService=class extends c.Disposable{constructor(e,t){super();d(this,"_interceptorsByName",new Map);this._context=e,this._docSkeletonManagerService=t;const n=this._docSkeletonManagerService.getViewModel(),s=n.getDataModel().getUnitId();if(s===c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||s===c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(n)),this.disposeWithMe(this.intercept(x.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(x.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(x.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(s=e.getDataModel().getCustomDecorations())!=null?s:[]})}})),t}};exports.DocInterceptorService=de([ge(1,c.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);function w(o,i=""){if(!i)return["body"];const{headers:e,footers:t}=o.getSnapshot();if(e==null&&t==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[i])!=null)return["headers",i,"body"];if((t==null?void 0:t[i])!=null)return["footers",i,"body"];throw new Error("Segment id not found in headers or footers")}function _e(o,i,e){const{unitId:t,segmentId:n}=i,r=o.get(c.IUniverInstanceService).getUnit(t);if(!r)return!1;const a={id:O.id,params:{unitId:i.unitId,actions:[],textRanges:void 0}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.add({...i,body:e});if(!u)return!1;const g=w(r,n);return a.params.actions=l.editOp(u.serialize(),g),a}function he(o,i){var I;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:r,selections:a}=i,l=o.get(exports.DocSelectionManagerService),u=o.get(c.IUniverInstanceService),g=a!=null?a:l.getTextRanges({unitId:r,subUnitId:r}),_=(I=g==null?void 0:g[0])==null?void 0:I.segmentId;if(!(g!=null&&g.length))return!1;const f=u.getUnit(r,c.UniverInstanceType.UNIVER_DOC);if(!f)return!1;const h=f.getSelfOrHeaderFooterModel(_).getBody();if(!h)return!1;const S=c.BuildTextUtils.customRange.add({ranges:g,rangeId:e,rangeType:t,segmentId:_,wholeEntity:n,properties:s,body:h});if(!S)return!1;const m=c.JSONX.getInstance(),p={id:O.id,params:{unitId:r,actions:[],textRanges:S.selections,segmentId:_},textX:S},R=w(f,_);return p.params.actions=m.editOp(S.serialize(),R),p}function Se(o,i){const{unitId:e,segmentId:t,insert:n}=i,r=o.get(c.IUniverInstanceService).getUnit(e);if(!r)return!1;const a={id:O.id,params:{unitId:i.unitId,actions:[],textRanges:void 0,segmentId:t}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.delete(o,{documentDataModel:r,rangeId:i.rangeId,insert:n,segmentId:t});if(!u)return!1;const g=w(r,t);return a.params.actions=l.editOp(u.serialize(),g),a.params.textRanges=u.selections,a}function fe(o,i){var S,m,p,R;const{unitId:e,body:t,doc:n}=i;let s=n;if(s||(s=o.get(c.IUniverInstanceService).getUnit(e)),!s)return!1;const r=(S=i.selection)==null?void 0:S.segmentId,a=(m=s.getSelfOrHeaderFooterModel(r))==null?void 0:m.getBody();if(!a)return!1;const l=o.get(exports.DocSelectionManagerService),u=(p=i.selection)!=null?p:l.getActiveTextRange();if(!u||!a)return!1;const g=(R=i.textRanges)!=null?R:[{startOffset:u.startOffset+t.dataStream.length,endOffset:u.startOffset+t.dataStream.length,collapsed:!0,segmentId:r}],_=c.BuildTextUtils.selection.replace({selection:u,body:t,doc:s});if(!_)return!1;const f={id:O.id,params:{unitId:e,actions:[],textRanges:g,debounce:!0,segmentId:r},textX:_},h=c.JSONX.getInstance();return f.params.actions=h.editOp(_.serialize()),f}exports.DOC_INTERCEPTOR_POINT=x;exports.DocStateEmitService=y;exports.RichTextEditingMutation=O;exports.SetTextSelectionsOperation=C;exports.addCustomRangeBySelectionFactory=he;exports.addCustomRangeFactory=_e;exports.deleteCustomRangeFactory=Se;exports.replaceSelectionFactory=fe;
1
+ "use strict";var k=Object.defineProperty;var z=(o,i,e)=>i in o?k(o,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[i]=e;var d=(o,i,e)=>z(o,typeof i!="symbol"?i+"":i,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),D=require("@univerjs/engine-render"),v=require("rxjs"),C={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 v.Subject);d(this,"textSelection$",this._textSelection$.asObservable());d(this,"_refreshSelection$",new v.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(v.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:D.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:_}=n,f=[...u,...g].filter(h=>h.startOffset!=null&&h.endOffset!=null).sort((h,S)=>h.startOffset>S.startOffset?1:h.startOffset<S.startOffset?-1:0);this._commandService.executeCommand(C.id,{unitId:s,subUnitId:r,segmentId:a,style:l,isEditing:_,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 K=Object.defineProperty,q=Object.getOwnPropertyDescriptor,H=(o,i,e,t)=>{for(var n=t>1?void 0:t?q(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&K(i,e,n),n},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 v.BehaviorSubject(null));d(this,"currentSkeleton$",this._currentSkeleton$.asObservable());d(this,"_currentSkeletonBefore$",new v.BehaviorSubject(null));d(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());d(this,"_currentViewModel$",new v.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(v.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 D.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new D.DocumentViewModel(e)}};exports.DocSkeletonManagerService=H([V(1,c.Inject(c.LocaleService)),V(2,c.IUniverInstanceService)],exports.DocSkeletonManagerService);class y extends c.RxDisposable{constructor(){super();d(this,"_docStateChangeParams$",new v.BehaviorSubject(null));d(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const A="doc.mutation.rich-text-editing",O={id:A,type:c.CommandType.MUTATION,handler:(o,i)=>{var $,B;const{unitId:e,segmentId:t="",actions:n,textRanges:s,prevTextRanges:r,trigger:a,noHistory:l,isCompositionEnd:u,noNeedSetTextRange:g,debounce:_,isEditing:f=!0,isSync:h,syncer:S}=i,m=o.get(c.IUniverInstanceService),p=o.get(D.IRenderManagerService),R=o.get(y),I=m.getUniverDocInstance(e),P=($=p.getRenderById(e))==null?void 0:$.with(exports.DocSkeletonManagerService).getViewModel();if(I==null||P==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const E=o.get(exports.DocSelectionManagerService),T=(B=E.getDocRanges())!=null?B:[],L=!!I.getSnapshot().disabled;if(c.JSONX.isNoop(n)||n&&n.length===0||L)return{unitId:e,actions:[],textRanges:T};const N=c.JSONX.invertWithDoc(n,I.getSnapshot());I.apply(n),P.reset(I),!g&&s&&a!=null&&queueMicrotask(()=>{E.replaceDocRanges(s,{unitId:e,subUnitId:e},f,i.options)});const G={commandId:A,unitId:e,segmentId:t,trigger:a,noHistory:l,debounce:_,redoState:{actions:n,textRanges:s},undoState:{actions:N,textRanges:r!=null?r:T},isCompositionEnd:u,isSync:h,syncer:S};return R.emitStateChangeInfo(G),{unitId:e,actions:N,textRanges:T}}},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",X={};var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(o,i,e,t)=>{for(var n=t>1?void 0:t?te(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ee(i,e,n),n},b=(o,i)=>(e,t)=>i(e,t,o);let M=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===C.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)}}))}};M=ne([b(0,c.ICommandService),b(1,c.Inject(exports.DocSelectionManagerService)),b(2,c.IUniverInstanceService)],M);var ie=Object.defineProperty,se=Object.getOwnPropertyDescriptor,re=(o,i,e,t)=>{for(var n=t>1?void 0:t?se(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ie(i,e,n),n},F=(o,i)=>(e,t)=>i(e,t,o);const oe="DOCS_PLUGIN";var U;exports.UniverDocsPlugin=(U=class extends c.Plugin{constructor(i=X,e,t){super(),this._config=i,this._injector=e,this._configService=t;const{...n}=c.merge({},X,this._config);this._configService.setConfig(Z,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[O,Q,C].forEach(i=>{this._injector.get(c.ICommandService).registerCommand(i)})}_initializeDependencies(){[[exports.DocSelectionManagerService],[y],[M]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(M)}},d(U,"pluginName",oe),U);exports.UniverDocsPlugin=re([F(1,c.Inject(c.Injector)),F(2,c.IConfigService)],exports.UniverDocsPlugin);const ce=c.createInterceptorKey("CUSTOM_RANGE"),ae=c.createInterceptorKey("CUSTOM_DECORATION"),x={CUSTOM_RANGE:ce,CUSTOM_DECORATION:ae};var le=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,de=(o,i,e,t)=>{for(var n=t>1?void 0:t?ue(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&le(i,e,n),n},ge=(o,i)=>(e,t)=>i(e,t,o);exports.DocInterceptorService=class extends c.Disposable{constructor(e,t){super();d(this,"_interceptorsByName",new Map);this._context=e,this._docSkeletonManagerService=t;const n=this._docSkeletonManagerService.getViewModel(),s=n.getDataModel().getUnitId();if(s===c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||s===c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(n)),this.disposeWithMe(this.intercept(x.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(x.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(x.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(s=e.getDataModel().getCustomDecorations())!=null?s:[]})}})),t}};exports.DocInterceptorService=de([ge(1,c.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);function w(o,i=""){if(!i)return["body"];const{headers:e,footers:t}=o.getSnapshot();if(e==null&&t==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[i])!=null)return["headers",i,"body"];if((t==null?void 0:t[i])!=null)return["footers",i,"body"];throw new Error("Segment id not found in headers or footers")}function _e(o,i,e){const{unitId:t,segmentId:n}=i,r=o.get(c.IUniverInstanceService).getUnit(t);if(!r)return!1;const a={id:O.id,params:{unitId:i.unitId,actions:[],textRanges:void 0}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.add({...i,body:e});if(!u)return!1;const g=w(r,n);return a.params.actions=l.editOp(u.serialize(),g),a}function he(o,i){var I;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:r,selections:a}=i,l=o.get(exports.DocSelectionManagerService),u=o.get(c.IUniverInstanceService),g=a!=null?a:l.getTextRanges({unitId:r,subUnitId:r}),_=(I=g==null?void 0:g[0])==null?void 0:I.segmentId;if(!(g!=null&&g.length))return!1;const f=u.getUnit(r,c.UniverInstanceType.UNIVER_DOC);if(!f)return!1;const h=f.getSelfOrHeaderFooterModel(_).getBody();if(!h)return!1;const S=c.BuildTextUtils.customRange.add({ranges:g,rangeId:e,rangeType:t,segmentId:_,wholeEntity:n,properties:s,body:h});if(!S)return!1;const m=c.JSONX.getInstance(),p={id:O.id,params:{unitId:r,actions:[],textRanges:S.selections,segmentId:_},textX:S},R=w(f,_);return p.params.actions=m.editOp(S.serialize(),R),p}function Se(o,i){const{unitId:e,segmentId:t,insert:n}=i,r=o.get(c.IUniverInstanceService).getUnit(e);if(!r)return!1;const a={id:O.id,params:{unitId:i.unitId,actions:[],textRanges:void 0,segmentId:t}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.delete(o,{documentDataModel:r,rangeId:i.rangeId,insert:n,segmentId:t});if(!u)return!1;const g=w(r,t);return a.params.actions=l.editOp(u.serialize(),g),a.params.textRanges=u.selections,a}function fe(o,i){var S,m,p,R;const{unitId:e,body:t,doc:n}=i;let s=n;if(s||(s=o.get(c.IUniverInstanceService).getUnit(e)),!s)return!1;const r=(S=i.selection)==null?void 0:S.segmentId,a=(m=s.getSelfOrHeaderFooterModel(r))==null?void 0:m.getBody();if(!a)return!1;const l=o.get(exports.DocSelectionManagerService),u=(p=i.selection)!=null?p:l.getActiveTextRange();if(!u||!a)return!1;const g=(R=i.textRanges)!=null?R:[{startOffset:u.startOffset+t.dataStream.length,endOffset:u.startOffset+t.dataStream.length,collapsed:!0,segmentId:r}],_=c.BuildTextUtils.selection.replace({selection:u,body:t,doc:s});if(!_)return!1;const f={id:O.id,params:{unitId:e,actions:[],textRanges:g,debounce:!0,segmentId:r},textX:_},h=c.JSONX.getInstance();return f.params.actions=h.editOp(_.serialize()),f}exports.DOC_INTERCEPTOR_POINT=x;exports.DocStateEmitService=y;exports.RichTextEditingMutation=O;exports.SetTextSelectionsOperation=C;exports.addCustomRangeBySelectionFactory=he;exports.addCustomRangeFactory=_e;exports.deleteCustomRangeFactory=Se;exports.replaceSelectionFactory=fe;
package/lib/es/index.js CHANGED
@@ -1,32 +1,32 @@
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 N, RxDisposable as V, UniverInstanceType as b, ICommandService as B, IUniverInstanceService as p, Inject as w, LocaleService as re, isInternalEditorID as oe, JSONX as O, Disposable as J, BuildTextUtils as C, 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 $, toDisposable as _e, remove as ge, 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 x, takeUntil as Z } from "rxjs";
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 N, RxDisposable as V, UniverInstanceType as b, ICommandService as B, IUniverInstanceService as p, Inject as w, LocaleService as oe, isInternalEditorID as ce, JSONX as O, Disposable as Q, BuildTextUtils as C, Injector as ae, Plugin as le, merge as ue, IConfigService as de, createInterceptorKey as Z, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as ge, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as _e, DisposableCollection as $, toDisposable as he, remove as fe, composeInterceptors as Se } from "@univerjs/core";
5
+ import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as pe, DocumentSkeleton as Ie, DocumentViewModel as me, IRenderManagerService as ve } from "@univerjs/engine-render";
6
+ import { Subject as Re, BehaviorSubject as x, takeUntil as ee } from "rxjs";
7
7
  const j = {
8
8
  id: "doc.operation.set-selections",
9
9
  type: N.OPERATION,
10
10
  handler: () => !0
11
11
  };
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--)
12
+ var Oe = Object.defineProperty, xe = Object.getOwnPropertyDescriptor, Ce = (i, e, t, n) => {
13
+ for (var s = n > 1 ? void 0 : n ? xe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
14
14
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
15
- return n && s && ve(e, t, s), s;
15
+ return n && s && Oe(e, t, s), s;
16
16
  }, W = (i, e) => (t, n) => e(t, n, i);
17
17
  let m = class extends V {
18
18
  constructor(e, t) {
19
19
  super();
20
20
  u(this, "_currentSelection", null);
21
21
  u(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
22
- u(this, "_textSelection$", new me());
22
+ u(this, "_textSelection$", new Re());
23
23
  u(this, "textSelection$", this._textSelection$.asObservable());
24
24
  u(this, "_refreshSelection$", new x(null));
25
25
  u(this, "refreshSelection$", this._refreshSelection$.asObservable());
26
26
  this._commandService = e, this._univerInstanceService = t, this._listenCurrentUnit();
27
27
  }
28
28
  _listenCurrentUnit() {
29
- this._univerInstanceService.getCurrentTypeOfUnit$(b.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((e) => {
29
+ this._univerInstanceService.getCurrentTypeOfUnit$(b.UNIVER_DOC).pipe(ee(this.dispose$)).subscribe((e) => {
30
30
  if (e == null)
31
31
  return;
32
32
  const t = e.getUnitId();
@@ -89,7 +89,7 @@ let m = class extends V {
89
89
  segmentId: "",
90
90
  segmentPage: -1,
91
91
  isEditing: t,
92
- style: fe
92
+ style: pe
93
93
  // mock style.
94
94
  });
95
95
  }
@@ -126,14 +126,14 @@ let m = class extends V {
126
126
  ...t
127
127
  };
128
128
  this._replaceByParam(n), this._textSelection$.next(n);
129
- const { unitId: s, subUnitId: r, segmentId: o, style: c, textRanges: a, rectRanges: l, isEditing: d } = n, g = [...a, ...l].filter((_) => _.startOffset != null && _.endOffset != null).sort((_, h) => _.startOffset > h.startOffset ? 1 : _.startOffset < h.startOffset ? -1 : 0);
129
+ const { unitId: s, subUnitId: r, segmentId: o, style: c, textRanges: a, rectRanges: l, isEditing: d } = n, _ = [...a, ...l].filter((g) => g.startOffset != null && g.endOffset != null).sort((g, h) => g.startOffset > h.startOffset ? 1 : g.startOffset < h.startOffset ? -1 : 0);
130
130
  this._commandService.executeCommand(j.id, {
131
131
  unitId: s,
132
132
  subUnitId: r,
133
133
  segmentId: o,
134
134
  style: c,
135
135
  isEditing: d,
136
- ranges: g
136
+ ranges: _
137
137
  });
138
138
  }
139
139
  dispose() {
@@ -172,14 +172,14 @@ let m = class extends V {
172
172
  r.has(n) ? r.get(n).textRanges.push(...e.textRanges) : r.set(n, { ...s });
173
173
  }
174
174
  };
175
- m = Oe([
175
+ m = Ce([
176
176
  W(0, B),
177
177
  W(1, p)
178
178
  ], m);
179
- var xe = Object.defineProperty, Ce = Object.getOwnPropertyDescriptor, Me = (i, e, t, n) => {
180
- for (var s = n > 1 ? void 0 : n ? Ce(e, t) : e, r = i.length - 1, o; r >= 0; r--)
179
+ var Me = Object.defineProperty, De = Object.getOwnPropertyDescriptor, Te = (i, e, t, n) => {
180
+ for (var s = n > 1 ? void 0 : n ? De(e, t) : e, r = i.length - 1, o; r >= 0; r--)
181
181
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
182
- return n && s && xe(e, t, s), s;
182
+ return n && s && Me(e, t, s), s;
183
183
  }, Y = (i, e) => (t, n) => e(t, n, i);
184
184
  let D = class extends V {
185
185
  constructor(e, t, n) {
@@ -193,7 +193,7 @@ let D = class extends V {
193
193
  u(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
194
194
  u(this, "_currentViewModel$", new x(null));
195
195
  u(this, "currentViewModel$", this._currentViewModel$.asObservable());
196
- this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(b.UNIVER_DOC).pipe(Z(this.dispose$)).subscribe((s) => {
196
+ this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(b.UNIVER_DOC).pipe(ee(this.dispose$)).subscribe((s) => {
197
197
  s && s.getUnitId() === this._context.unitId && this._update(s);
198
198
  });
199
199
  }
@@ -214,22 +214,22 @@ let D = class extends V {
214
214
  const t = this._context.unitId;
215
215
  if (e.getBody() == null)
216
216
  return;
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));
217
+ 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));
218
218
  const n = this._skeleton;
219
219
  n.calculate(), this._currentSkeletonBefore$.next(n), this._currentSkeleton$.next(n), this._currentViewModel$.next(this._docViewModel);
220
220
  }
221
221
  _buildSkeleton(e) {
222
- return Se.create(e, this._localeService);
222
+ return Ie.create(e, this._localeService);
223
223
  }
224
224
  _buildDocViewModel(e) {
225
- return new pe(e);
225
+ return new me(e);
226
226
  }
227
227
  };
228
- D = Me([
229
- Y(1, w(re)),
228
+ D = Te([
229
+ Y(1, w(oe)),
230
230
  Y(2, p)
231
231
  ], D);
232
- class ee extends V {
232
+ class te extends V {
233
233
  constructor() {
234
234
  super();
235
235
  u(this, "_docStateChangeParams$", new x(null));
@@ -258,15 +258,15 @@ const K = "doc.mutation.rich-text-editing", M = {
258
258
  noHistory: a,
259
259
  isCompositionEnd: l,
260
260
  noNeedSetTextRange: d,
261
- debounce: g,
262
- isEditing: _ = !0,
261
+ debounce: _,
262
+ isEditing: g = !0,
263
263
  isSync: h,
264
264
  syncer: f
265
- } = e, v = i.get(p), I = i.get(Ie), R = i.get(ee), S = v.getUniverDocInstance(t), L = (z = I.getRenderById(t)) == null ? void 0 : z.with(D).getViewModel();
265
+ } = e, v = i.get(p), I = i.get(ve), R = i.get(te), S = v.getUniverDocInstance(t), L = (z = I.getRenderById(t)) == null ? void 0 : z.with(D).getViewModel();
266
266
  if (S == null || L == null)
267
267
  throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
268
- const X = i.get(m), y = (F = X.getDocRanges()) != null ? F : [], te = !!S.getSnapshot().disabled;
269
- if (O.isNoop(s) || s && s.length === 0 || te)
268
+ const X = i.get(m), y = (F = X.getDocRanges()) != null ? F : [], ne = !!S.getSnapshot().disabled;
269
+ if (O.isNoop(s) || s && s.length === 0 || ne)
270
270
  return {
271
271
  unitId: t,
272
272
  actions: [],
@@ -274,15 +274,15 @@ const K = "doc.mutation.rich-text-editing", M = {
274
274
  };
275
275
  const G = O.invertWithDoc(s, S.getSnapshot());
276
276
  S.apply(s), L.reset(S), !d && r && c != null && queueMicrotask(() => {
277
- X.replaceDocRanges(r, { unitId: t, subUnitId: t }, _, e.options);
277
+ X.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
278
278
  });
279
- const ne = {
279
+ const se = {
280
280
  commandId: K,
281
281
  unitId: t,
282
282
  segmentId: n,
283
283
  trigger: c,
284
284
  noHistory: a,
285
- debounce: g,
285
+ debounce: _,
286
286
  redoState: {
287
287
  actions: s,
288
288
  textRanges: r
@@ -295,26 +295,26 @@ const K = "doc.mutation.rich-text-editing", M = {
295
295
  isSync: h,
296
296
  syncer: f
297
297
  };
298
- return R.emitStateChangeInfo(ne), {
298
+ return R.emitStateChangeInfo(se), {
299
299
  unitId: t,
300
300
  actions: G,
301
301
  textRanges: y
302
302
  };
303
303
  }
304
- }, De = {
304
+ }, be = {
305
305
  id: "doc.mutation.rename-doc",
306
306
  type: N.MUTATION,
307
307
  handler: (i, e) => {
308
308
  const n = i.get(p).getUnit(e.unitId, b.UNIVER_DOC);
309
309
  return n ? (n.setName(e.name), !0) : !1;
310
310
  }
311
- }, Te = "docs.config", be = {};
312
- var we = Object.defineProperty, ye = Object.getOwnPropertyDescriptor, $e = (i, e, t, n) => {
313
- for (var s = n > 1 ? void 0 : n ? ye(e, t) : e, r = i.length - 1, o; r >= 0; r--)
311
+ }, we = "docs.config", H = {};
312
+ var ye = Object.defineProperty, $e = Object.getOwnPropertyDescriptor, Ue = (i, e, t, n) => {
313
+ for (var s = n > 1 ? void 0 : n ? $e(e, t) : e, r = i.length - 1, o; r >= 0; r--)
314
314
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
315
- return n && s && we(e, t, s), s;
315
+ return n && s && ye(e, t, s), s;
316
316
  }, U = (i, e) => (t, n) => e(t, n, i);
317
- let T = class extends J {
317
+ let T = class extends Q {
318
318
  constructor(i, e, t) {
319
319
  super(), this._commandService = i, this._textSelectionManagerService = e, this._univerInstanceService = t, this._initSelectionChange();
320
320
  }
@@ -346,24 +346,28 @@ let T = class extends J {
346
346
  }));
347
347
  }
348
348
  };
349
- T = $e([
349
+ T = Ue([
350
350
  U(0, B),
351
351
  U(1, w(m)),
352
352
  U(2, p)
353
353
  ], T);
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--)
354
+ var Ee = Object.defineProperty, Pe = Object.getOwnPropertyDescriptor, Ne = (i, e, t, n) => {
355
+ for (var s = n > 1 ? void 0 : n ? Pe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
356
356
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
357
- return n && s && Ue(e, t, s), s;
358
- }, H = (i, e) => (t, n) => e(t, n, i);
359
- const Ne = "DOCS_PLUGIN";
357
+ return n && s && Ee(e, t, s), s;
358
+ }, k = (i, e) => (t, n) => e(t, n, i);
359
+ const Ve = "DOCS_PLUGIN";
360
360
  var P;
361
- let k = (P = class extends ae {
361
+ let q = (P = class extends le {
362
362
  // static override type = UniverInstanceType.UNIVER_DOC;
363
- constructor(i = be, e, t) {
363
+ constructor(i = H, e, t) {
364
364
  super(), this._config = i, this._injector = e, this._configService = t;
365
- const { ...n } = this._config;
366
- this._configService.setConfig(Te, n);
365
+ const { ...n } = ue(
366
+ {},
367
+ H,
368
+ this._config
369
+ );
370
+ this._configService.setConfig(we, n);
367
371
  }
368
372
  onStarting() {
369
373
  this._initializeDependencies(), this._initializeCommands();
@@ -371,7 +375,7 @@ let k = (P = class extends ae {
371
375
  _initializeCommands() {
372
376
  [
373
377
  M,
374
- De,
378
+ be,
375
379
  j
376
380
  ].forEach((i) => {
377
381
  this._injector.get(B).registerCommand(i);
@@ -380,34 +384,34 @@ let k = (P = class extends ae {
380
384
  _initializeDependencies() {
381
385
  [
382
386
  [m],
383
- [ee],
387
+ [te],
384
388
  [T]
385
389
  ].forEach((i) => this._injector.add(i));
386
390
  }
387
391
  onReady() {
388
392
  this._injector.get(T);
389
393
  }
390
- }, u(P, "pluginName", Ne), P);
391
- k = Pe([
392
- H(1, w(ce)),
393
- H(2, le)
394
- ], k);
395
- const Ve = Q("CUSTOM_RANGE"), Be = Q("CUSTOM_DECORATION"), E = {
396
- CUSTOM_RANGE: Ve,
397
- CUSTOM_DECORATION: Be
394
+ }, u(P, "pluginName", Ve), P);
395
+ q = Ne([
396
+ k(1, w(ae)),
397
+ k(2, de)
398
+ ], q);
399
+ const Be = Z("CUSTOM_RANGE"), je = Z("CUSTOM_DECORATION"), E = {
400
+ CUSTOM_RANGE: Be,
401
+ CUSTOM_DECORATION: je
398
402
  };
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--)
403
+ var Ae = Object.defineProperty, Le = Object.getOwnPropertyDescriptor, Xe = (i, e, t, n) => {
404
+ for (var s = n > 1 ? void 0 : n ? Le(e, t) : e, r = i.length - 1, o; r >= 0; r--)
401
405
  (o = i[r]) && (s = (n ? o(e, t, s) : o(s)) || s);
402
- return n && s && je(e, t, s), s;
403
- }, Xe = (i, e) => (t, n) => e(t, n, i);
404
- let q = class extends J {
406
+ return n && s && Ae(e, t, s), s;
407
+ }, Ge = (i, e) => (t, n) => e(t, n, i);
408
+ let J = class extends Q {
405
409
  constructor(e, t) {
406
410
  super();
407
411
  u(this, "_interceptorsByName", /* @__PURE__ */ new Map());
408
412
  this._context = e, this._docSkeletonManagerService = t;
409
413
  const n = this._docSkeletonManagerService.getViewModel(), s = n.getDataModel().getUnitId();
410
- if (s === ue || s === de)
414
+ if (s === ge || s === _e)
411
415
  return;
412
416
  this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(E.CUSTOM_RANGE, {
413
417
  priority: -1,
@@ -430,11 +434,11 @@ let q = class extends J {
430
434
  var c, a;
431
435
  return ((c = o.priority) != null ? c : 0) - ((a = r.priority) != null ? a : 0);
432
436
  })
433
- ), this.disposeWithMe(_e(() => ge(this._interceptorsByName.get(n), t)));
437
+ ), this.disposeWithMe(he(() => fe(this._interceptorsByName.get(n), t)));
434
438
  }
435
439
  fetchThroughInterceptors(e) {
436
440
  const t = e, n = this._interceptorsByName.get(t);
437
- return he(n || []);
441
+ return Se(n || []);
438
442
  }
439
443
  interceptDocumentViewModel(e) {
440
444
  const t = new $();
@@ -464,9 +468,9 @@ let q = class extends J {
464
468
  })), t;
465
469
  }
466
470
  };
467
- q = Le([
468
- Xe(1, w(D))
469
- ], q);
471
+ J = Xe([
472
+ Ge(1, w(D))
473
+ ], J);
470
474
  function A(i, e = "") {
471
475
  if (!e)
472
476
  return ["body"];
@@ -479,7 +483,7 @@ function A(i, e = "") {
479
483
  return ["footers", e, "body"];
480
484
  throw new Error("Segment id not found in headers or footers");
481
485
  }
482
- function Ye(i, e, t) {
486
+ function Ke(i, e, t) {
483
487
  const { unitId: n, segmentId: s } = e, o = i.get(p).getUnit(n);
484
488
  if (!o)
485
489
  return !1;
@@ -496,22 +500,22 @@ function Ye(i, e, t) {
496
500
  const d = A(o, s);
497
501
  return c.params.actions = a.editOp(l.serialize(), d), c;
498
502
  }
499
- function Ke(i, e) {
503
+ function He(i, e) {
500
504
  var S;
501
- const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selections: c } = e, a = i.get(m), l = i.get(p), d = c != null ? c : a.getTextRanges({ unitId: o, subUnitId: o }), g = (S = d == null ? void 0 : d[0]) == null ? void 0 : S.segmentId;
505
+ const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selections: c } = e, a = i.get(m), l = i.get(p), d = c != null ? c : a.getTextRanges({ unitId: o, subUnitId: o }), _ = (S = d == null ? void 0 : d[0]) == null ? void 0 : S.segmentId;
502
506
  if (!(d != null && d.length))
503
507
  return !1;
504
- const _ = l.getUnit(o, b.UNIVER_DOC);
505
- if (!_)
508
+ const g = l.getUnit(o, b.UNIVER_DOC);
509
+ if (!g)
506
510
  return !1;
507
- const h = _.getSelfOrHeaderFooterModel(g).getBody();
511
+ const h = g.getSelfOrHeaderFooterModel(_).getBody();
508
512
  if (!h)
509
513
  return !1;
510
514
  const f = C.customRange.add({
511
515
  ranges: d,
512
516
  rangeId: t,
513
517
  rangeType: n,
514
- segmentId: g,
518
+ segmentId: _,
515
519
  wholeEntity: s,
516
520
  properties: r,
517
521
  body: h
@@ -524,13 +528,13 @@ function Ke(i, e) {
524
528
  unitId: o,
525
529
  actions: [],
526
530
  textRanges: f.selections,
527
- segmentId: g
531
+ segmentId: _
528
532
  },
529
533
  textX: f
530
- }, R = A(_, g);
534
+ }, R = A(g, _);
531
535
  return I.params.actions = v.editOp(f.serialize(), R), I;
532
536
  }
533
- function He(i, e) {
537
+ function ke(i, e) {
534
538
  const { unitId: t, segmentId: n, insert: s } = e, o = i.get(p).getUnit(t);
535
539
  if (!o)
536
540
  return !1;
@@ -553,7 +557,7 @@ function He(i, e) {
553
557
  const d = A(o, n);
554
558
  return c.params.actions = a.editOp(l.serialize(), d), c.params.textRanges = l.selections, c;
555
559
  }
556
- function ke(i, e) {
560
+ function qe(i, e) {
557
561
  var f, v, I, R;
558
562
  const { unitId: t, body: n, doc: s } = e;
559
563
  let r = s;
@@ -569,14 +573,14 @@ function ke(i, e) {
569
573
  endOffset: l.startOffset + n.dataStream.length,
570
574
  collapsed: !0,
571
575
  segmentId: o
572
- }], g = C.selection.replace({
576
+ }], _ = C.selection.replace({
573
577
  selection: l,
574
578
  body: n,
575
579
  doc: r
576
580
  });
577
- if (!g)
581
+ if (!_)
578
582
  return !1;
579
- const _ = {
583
+ const g = {
580
584
  id: M.id,
581
585
  params: {
582
586
  unitId: t,
@@ -585,21 +589,21 @@ function ke(i, e) {
585
589
  debounce: !0,
586
590
  segmentId: o
587
591
  },
588
- textX: g
592
+ textX: _
589
593
  }, h = O.getInstance();
590
- return _.params.actions = h.editOp(g.serialize()), _;
594
+ return g.params.actions = h.editOp(_.serialize()), g;
591
595
  }
592
596
  export {
593
597
  E as DOC_INTERCEPTOR_POINT,
594
- q as DocInterceptorService,
598
+ J as DocInterceptorService,
595
599
  m as DocSelectionManagerService,
596
600
  D as DocSkeletonManagerService,
597
- ee as DocStateEmitService,
601
+ te as DocStateEmitService,
598
602
  M as RichTextEditingMutation,
599
603
  j as SetTextSelectionsOperation,
600
- k as UniverDocsPlugin,
601
- Ke as addCustomRangeBySelectionFactory,
602
- Ye as addCustomRangeFactory,
603
- He as deleteCustomRangeFactory,
604
- ke as replaceSelectionFactory
604
+ q as UniverDocsPlugin,
605
+ He as addCustomRangeBySelectionFactory,
606
+ Ke as addCustomRangeFactory,
607
+ ke as deleteCustomRangeFactory,
608
+ qe as replaceSelectionFactory
605
609
  };
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")):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,m){"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 w;const M={id:"doc.operation.set-selections",type:r.CommandType.OPERATION,handler:()=>!0};var L=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&&L(i,e,n),n},E=(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 m.Subject);g(this,"textSelection$",this._textSelection$.asObservable());g(this,"_refreshSelection$",new m.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(m.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=e.getUnitId();this._setCurrentSelectionNotRefresh({unitId:t,subUnitId:t})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(e=this._currentSelection){return this._getTextRanges(e)}refreshSelection(e=this._currentSelection){e!=null&&this._refresh(e)}__TEST_ONLY_setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}getTextRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.textRanges}getRectRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.rectRanges}getDocRanges(e=this._currentSelection){var o,a;const t=(o=this.getTextRanges(e))!=null?o:[],n=(a=this.getRectRanges(e))!=null?a:[];return[...t,...n].filter(u=>u.startOffset!=null&&u.endOffset!=null).sort((u,d)=>u.startOffset>d.startOffset?1:u.startOffset<d.startOffset?-1:0)}getActiveTextRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t}=e;return t.find(n=>n.isActive)}getActiveRectRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{rectRanges:t}=e;return t.find(n=>n.isActive)}__TEST_ONLY_add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:"",segmentPage:-1,isEditing:t,style:v.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,s){if(t==null)return;const{unitId:o,subUnitId:a}=t;this._refreshSelection$.next({unitId:o,subUnitId:a,docRanges:e,isEditing:n,options:s})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;const n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:s,subUnitId:o,segmentId:a,style:u,textRanges:d,rectRanges:_,isEditing:h}=n,I=[...d,..._].filter(f=>f.startOffset!=null&&f.endOffset!=null).sort((f,S)=>f.startOffset>S.startOffset?1:f.startOffset<S.startOffset?-1:0);this._commandService.executeCommand(M.id,{unitId:s,subUnitId:o,segmentId:a,style:u,isEditing:h,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([E(0,r.ICommandService),E(1,r.IUniverInstanceService)],l.DocSelectionManagerService);var z=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&&z(i,e,n),n},N=(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 m.BehaviorSubject(null));g(this,"currentSkeleton$",this._currentSkeleton$.asObservable());g(this,"_currentSkeletonBefore$",new m.BehaviorSubject(null));g(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());g(this,"_currentViewModel$",new m.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(m.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([N(1,r.Inject(r.LocaleService)),N(2,r.IUniverInstanceService)],l.DocSkeletonManagerService);class U extends r.RxDisposable{constructor(){super();g(this,"_docStateChangeParams$",new m.BehaviorSubject(null));g(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const $="doc.mutation.rich-text-editing",O={id:$,type:r.CommandType.MUTATION,handler:(c,i)=>{var X,F;const{unitId:e,segmentId:t="",actions:n,textRanges:s,prevTextRanges:o,trigger:a,noHistory:u,isCompositionEnd:d,noNeedSetTextRange:_,debounce:h,isEditing:I=!0,isSync:f,syncer:S}=i,D=c.get(r.IUniverInstanceService),R=c.get(v.IRenderManagerService),C=c.get(U),p=D.getUniverDocInstance(e),j=(X=R.getRenderById(e))==null?void 0:X.with(l.DocSkeletonManagerService).getViewModel();if(p==null||j==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const V=c.get(l.DocSelectionManagerService),P=(F=V.getDocRanges())!=null?F:[],he=!!p.getSnapshot().disabled;if(r.JSONX.isNoop(n)||n&&n.length===0||he)return{unitId:e,actions:[],textRanges:P};const A=r.JSONX.invertWithDoc(n,p.getSnapshot());p.apply(n),j.reset(p),!_&&s&&a!=null&&queueMicrotask(()=>{V.replaceDocRanges(s,{unitId:e,subUnitId:e},I,i.options)});const fe={commandId:$,unitId:e,segmentId:t,trigger:a,noHistory:u,debounce:h,redoState:{actions:n,textRanges:s},undoState:{actions:A,textRanges:o!=null?o:P},isCompositionEnd:d,isSync:f,syncer:S};return C.emitStateChangeInfo(fe),{unitId:e,actions:A,textRanges:P}}},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},b=(c,i)=>(e,t)=>i(e,t,c);let T=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===M.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)}}))}};T=Z([b(0,r.ICommandService),b(1,r.Inject(l.DocSelectionManagerService)),b(2,r.IUniverInstanceService)],T);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},B=(c,i)=>(e,t)=>i(e,t,c);const ie="DOCS_PLUGIN";l.UniverDocsPlugin=(w=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(){[O,Y,M].forEach(i=>{this._injector.get(r.ICommandService).registerCommand(i)})}_initializeDependencies(){[[l.DocSelectionManagerService],[U],[T]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(T)}},g(w,"pluginName",ie),w),l.UniverDocsPlugin=ne([B(1,r.Inject(r.Injector)),B(2,r.IConfigService)],l.UniverDocsPlugin);const se=r.createInterceptorKey("CUSTOM_RANGE"),re=r.createInterceptorKey("CUSTOM_DECORATION"),x={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(x.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(x.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(x.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:O.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 p;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:o,selections:a}=i,u=c.get(l.DocSelectionManagerService),d=c.get(r.IUniverInstanceService),_=a!=null?a:u.getTextRanges({unitId:o,subUnitId:o}),h=(p=_==null?void 0:_[0])==null?void 0:p.segmentId;if(!(_!=null&&_.length))return!1;const I=d.getUnit(o,r.UniverInstanceType.UNIVER_DOC);if(!I)return!1;const f=I.getSelfOrHeaderFooterModel(h).getBody();if(!f)return!1;const S=r.BuildTextUtils.customRange.add({ranges:_,rangeId:e,rangeType:t,segmentId:h,wholeEntity:n,properties:s,body:f});if(!S)return!1;const D=r.JSONX.getInstance(),R={id:O.id,params:{unitId:o,actions:[],textRanges:S.selections,segmentId:h},textX:S},C=y(I,h);return R.params.actions=D.editOp(S.serialize(),C),R}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:O.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 S,D,R,C;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=(S=i.selection)==null?void 0:S.segmentId,a=(D=s.getSelfOrHeaderFooterModel(o))==null?void 0:D.getBody();if(!a)return!1;const u=c.get(l.DocSelectionManagerService),d=(R=i.selection)!=null?R:u.getActiveTextRange();if(!d||!a)return!1;const _=(C=i.textRanges)!=null?C:[{startOffset:d.startOffset+t.dataStream.length,endOffset:d.startOffset+t.dataStream.length,collapsed:!0,segmentId:o}],h=r.BuildTextUtils.selection.replace({selection:d,body:t,doc:s});if(!h)return!1;const I={id:O.id,params:{unitId:e,actions:[],textRanges:_,debounce:!0,segmentId:o},textX:h},f=r.JSONX.getInstance();return I.params.actions=f.editOp(h.serialize()),I}l.DOC_INTERCEPTOR_POINT=x,l.DocStateEmitService=U,l.RichTextEditingMutation=O,l.SetTextSelectionsOperation=M,l.addCustomRangeBySelectionFactory=de,l.addCustomRangeFactory=ue,l.deleteCustomRangeFactory=ge,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,m){"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 w;const M={id:"doc.operation.set-selections",type:r.CommandType.OPERATION,handler:()=>!0};var G=Object.defineProperty,k=Object.getOwnPropertyDescriptor,z=(c,i,e,t)=>{for(var n=t>1?void 0:t?k(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&&G(i,e,n),n},E=(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 m.Subject);g(this,"textSelection$",this._textSelection$.asObservable());g(this,"_refreshSelection$",new m.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(m.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=e.getUnitId();this._setCurrentSelectionNotRefresh({unitId:t,subUnitId:t})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(e=this._currentSelection){return this._getTextRanges(e)}refreshSelection(e=this._currentSelection){e!=null&&this._refresh(e)}__TEST_ONLY_setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}getTextRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.textRanges}getRectRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.rectRanges}getDocRanges(e=this._currentSelection){var o,a;const t=(o=this.getTextRanges(e))!=null?o:[],n=(a=this.getRectRanges(e))!=null?a:[];return[...t,...n].filter(u=>u.startOffset!=null&&u.endOffset!=null).sort((u,d)=>u.startOffset>d.startOffset?1:u.startOffset<d.startOffset?-1:0)}getActiveTextRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t}=e;return t.find(n=>n.isActive)}getActiveRectRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{rectRanges:t}=e;return t.find(n=>n.isActive)}__TEST_ONLY_add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:"",segmentPage:-1,isEditing:t,style:v.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,s){if(t==null)return;const{unitId:o,subUnitId:a}=t;this._refreshSelection$.next({unitId:o,subUnitId:a,docRanges:e,isEditing:n,options:s})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;const n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:s,subUnitId:o,segmentId:a,style:u,textRanges:d,rectRanges:_,isEditing:h}=n,I=[...d,..._].filter(f=>f.startOffset!=null&&f.endOffset!=null).sort((f,S)=>f.startOffset>S.startOffset?1:f.startOffset<S.startOffset?-1:0);this._commandService.executeCommand(M.id,{unitId:s,subUnitId:o,segmentId:a,style:u,isEditing:h,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=z([E(0,r.ICommandService),E(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},N=(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 m.BehaviorSubject(null));g(this,"currentSkeleton$",this._currentSkeleton$.asObservable());g(this,"_currentSkeletonBefore$",new m.BehaviorSubject(null));g(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());g(this,"_currentViewModel$",new m.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(m.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([N(1,r.Inject(r.LocaleService)),N(2,r.IUniverInstanceService)],l.DocSkeletonManagerService);class U extends r.RxDisposable{constructor(){super();g(this,"_docStateChangeParams$",new m.BehaviorSubject(null));g(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const $="doc.mutation.rich-text-editing",O={id:$,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:_,debounce:h,isEditing:I=!0,isSync:f,syncer:S}=i,D=c.get(r.IUniverInstanceService),R=c.get(v.IRenderManagerService),C=c.get(U),p=D.getUniverDocInstance(e),V=(F=R.getRenderById(e))==null?void 0:F.with(l.DocSkeletonManagerService).getViewModel();if(p==null||V==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const A=c.get(l.DocSelectionManagerService),P=(L=A.getDocRanges())!=null?L:[],he=!!p.getSnapshot().disabled;if(r.JSONX.isNoop(n)||n&&n.length===0||he)return{unitId:e,actions:[],textRanges:P};const X=r.JSONX.invertWithDoc(n,p.getSnapshot());p.apply(n),V.reset(p),!_&&s&&a!=null&&queueMicrotask(()=>{A.replaceDocRanges(s,{unitId:e,subUnitId:e},I,i.options)});const fe={commandId:$,unitId:e,segmentId:t,trigger:a,noHistory:u,debounce:h,redoState:{actions:n,textRanges:s},undoState:{actions:X,textRanges:o!=null?o:P},isCompositionEnd:d,isSync:f,syncer:S};return C.emitStateChangeInfo(fe),{unitId:e,actions:X,textRanges:P}}},K={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}},q="docs.config",B={};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},b=(c,i)=>(e,t)=>i(e,t,c);let T=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===M.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)}}))}};T=Z([b(0,r.ICommandService),b(1,r.Inject(l.DocSelectionManagerService)),b(2,r.IUniverInstanceService)],T);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},j=(c,i)=>(e,t)=>i(e,t,c);const ie="DOCS_PLUGIN";l.UniverDocsPlugin=(w=class extends r.Plugin{constructor(i=B,e,t){super(),this._config=i,this._injector=e,this._configService=t;const{...n}=r.merge({},B,this._config);this._configService.setConfig(q,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[O,K,M].forEach(i=>{this._injector.get(r.ICommandService).registerCommand(i)})}_initializeDependencies(){[[l.DocSelectionManagerService],[U],[T]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(T)}},g(w,"pluginName",ie),w),l.UniverDocsPlugin=ne([j(1,r.Inject(r.Injector)),j(2,r.IConfigService)],l.UniverDocsPlugin);const se=r.createInterceptorKey("CUSTOM_RANGE"),re=r.createInterceptorKey("CUSTOM_DECORATION"),x={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(x.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(x.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(x.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:O.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 p;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:o,selections:a}=i,u=c.get(l.DocSelectionManagerService),d=c.get(r.IUniverInstanceService),_=a!=null?a:u.getTextRanges({unitId:o,subUnitId:o}),h=(p=_==null?void 0:_[0])==null?void 0:p.segmentId;if(!(_!=null&&_.length))return!1;const I=d.getUnit(o,r.UniverInstanceType.UNIVER_DOC);if(!I)return!1;const f=I.getSelfOrHeaderFooterModel(h).getBody();if(!f)return!1;const S=r.BuildTextUtils.customRange.add({ranges:_,rangeId:e,rangeType:t,segmentId:h,wholeEntity:n,properties:s,body:f});if(!S)return!1;const D=r.JSONX.getInstance(),R={id:O.id,params:{unitId:o,actions:[],textRanges:S.selections,segmentId:h},textX:S},C=y(I,h);return R.params.actions=D.editOp(S.serialize(),C),R}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:O.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 S,D,R,C;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=(S=i.selection)==null?void 0:S.segmentId,a=(D=s.getSelfOrHeaderFooterModel(o))==null?void 0:D.getBody();if(!a)return!1;const u=c.get(l.DocSelectionManagerService),d=(R=i.selection)!=null?R:u.getActiveTextRange();if(!d||!a)return!1;const _=(C=i.textRanges)!=null?C:[{startOffset:d.startOffset+t.dataStream.length,endOffset:d.startOffset+t.dataStream.length,collapsed:!0,segmentId:o}],h=r.BuildTextUtils.selection.replace({selection:d,body:t,doc:s});if(!h)return!1;const I={id:O.id,params:{unitId:e,actions:[],textRanges:_,debounce:!0,segmentId:o},textX:h},f=r.JSONX.getInstance();return I.params.actions=f.editOp(h.serialize()),I}l.DOC_INTERCEPTOR_POINT=x,l.DocStateEmitService=U,l.RichTextEditingMutation=O,l.SetTextSelectionsOperation=M,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.5.1",
3
+ "version": "0.5.2-nightly.202412291605",
4
4
  "private": false,
5
5
  "description": "UniverSheet normal base-docs",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -48,15 +48,15 @@
48
48
  "rxjs": ">=7.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@univerjs/core": "0.5.1",
52
- "@univerjs/engine-render": "0.5.1"
51
+ "@univerjs/engine-render": "0.5.2-nightly.202412291605",
52
+ "@univerjs/core": "0.5.2-nightly.202412291605"
53
53
  },
54
54
  "devDependencies": {
55
55
  "rxjs": "^7.8.1",
56
56
  "typescript": "^5.7.2",
57
- "vite": "^6.0.1",
58
- "vitest": "^2.1.6",
59
- "@univerjs-infra/shared": "0.5.1"
57
+ "vite": "^6.0.3",
58
+ "vitest": "^2.1.8",
59
+ "@univerjs-infra/shared": "0.5.2"
60
60
  },
61
61
  "space": {
62
62
  ".": {
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS