@univerjs/docs 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +98 -94
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
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
|
|
2
|
-
var
|
|
3
|
-
var u = (i, e, t) =>
|
|
4
|
-
import { CommandType as N, RxDisposable as V, UniverInstanceType as b, ICommandService as B, IUniverInstanceService as p, Inject as w, LocaleService as
|
|
5
|
-
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as
|
|
6
|
-
import { Subject as
|
|
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
|
|
13
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
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 &&
|
|
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
|
|
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(
|
|
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:
|
|
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,
|
|
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:
|
|
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 =
|
|
175
|
+
m = Ce([
|
|
176
176
|
W(0, B),
|
|
177
177
|
W(1, p)
|
|
178
178
|
], m);
|
|
179
|
-
var
|
|
180
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
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 &&
|
|
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(
|
|
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 &&
|
|
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
|
|
222
|
+
return Ie.create(e, this._localeService);
|
|
223
223
|
}
|
|
224
224
|
_buildDocViewModel(e) {
|
|
225
|
-
return new
|
|
225
|
+
return new me(e);
|
|
226
226
|
}
|
|
227
227
|
};
|
|
228
|
-
D =
|
|
229
|
-
Y(1, w(
|
|
228
|
+
D = Te([
|
|
229
|
+
Y(1, w(oe)),
|
|
230
230
|
Y(2, p)
|
|
231
231
|
], D);
|
|
232
|
-
class
|
|
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:
|
|
262
|
-
isEditing:
|
|
261
|
+
debounce: _,
|
|
262
|
+
isEditing: g = !0,
|
|
263
263
|
isSync: h,
|
|
264
264
|
syncer: f
|
|
265
|
-
} = e, v = i.get(p), I = i.get(
|
|
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 : [],
|
|
269
|
-
if (O.isNoop(s) || s && s.length === 0 ||
|
|
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 },
|
|
277
|
+
X.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
|
|
278
278
|
});
|
|
279
|
-
const
|
|
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:
|
|
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(
|
|
298
|
+
return R.emitStateChangeInfo(se), {
|
|
299
299
|
unitId: t,
|
|
300
300
|
actions: G,
|
|
301
301
|
textRanges: y
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
|
-
},
|
|
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
|
-
},
|
|
312
|
-
var
|
|
313
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
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 &&
|
|
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
|
|
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 =
|
|
349
|
+
T = Ue([
|
|
350
350
|
U(0, B),
|
|
351
351
|
U(1, w(m)),
|
|
352
352
|
U(2, p)
|
|
353
353
|
], T);
|
|
354
|
-
var
|
|
355
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
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 &&
|
|
358
|
-
},
|
|
359
|
-
const
|
|
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
|
|
361
|
+
let q = (P = class extends le {
|
|
362
362
|
// static override type = UniverInstanceType.UNIVER_DOC;
|
|
363
|
-
constructor(i =
|
|
363
|
+
constructor(i = H, e, t) {
|
|
364
364
|
super(), this._config = i, this._injector = e, this._configService = t;
|
|
365
|
-
const { ...n } =
|
|
366
|
-
|
|
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
|
-
|
|
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
|
-
[
|
|
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",
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
],
|
|
395
|
-
const
|
|
396
|
-
CUSTOM_RANGE:
|
|
397
|
-
CUSTOM_DECORATION:
|
|
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
|
|
400
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
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 &&
|
|
403
|
-
},
|
|
404
|
-
let
|
|
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 ===
|
|
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(
|
|
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
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
],
|
|
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
|
|
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
|
|
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 }),
|
|
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
|
|
505
|
-
if (!
|
|
508
|
+
const g = l.getUnit(o, b.UNIVER_DOC);
|
|
509
|
+
if (!g)
|
|
506
510
|
return !1;
|
|
507
|
-
const h =
|
|
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:
|
|
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:
|
|
531
|
+
segmentId: _
|
|
528
532
|
},
|
|
529
533
|
textX: f
|
|
530
|
-
}, R = A(
|
|
534
|
+
}, R = A(g, _);
|
|
531
535
|
return I.params.actions = v.editOp(f.serialize(), R), I;
|
|
532
536
|
}
|
|
533
|
-
function
|
|
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
|
|
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
|
-
}],
|
|
576
|
+
}], _ = C.selection.replace({
|
|
573
577
|
selection: l,
|
|
574
578
|
body: n,
|
|
575
579
|
doc: r
|
|
576
580
|
});
|
|
577
|
-
if (!
|
|
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:
|
|
592
|
+
textX: _
|
|
589
593
|
}, h = O.getInstance();
|
|
590
|
-
return
|
|
594
|
+
return g.params.actions = h.editOp(_.serialize()), g;
|
|
591
595
|
}
|
|
592
596
|
export {
|
|
593
597
|
E as DOC_INTERCEPTOR_POINT,
|
|
594
|
-
|
|
598
|
+
J as DocInterceptorService,
|
|
595
599
|
m as DocSelectionManagerService,
|
|
596
600
|
D as DocSkeletonManagerService,
|
|
597
|
-
|
|
601
|
+
te as DocStateEmitService,
|
|
598
602
|
M as RichTextEditingMutation,
|
|
599
603
|
j as SetTextSelectionsOperation,
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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.
|
|
3
|
+
"version": "0.5.2",
|
|
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/
|
|
52
|
-
"@univerjs/
|
|
51
|
+
"@univerjs/engine-render": "0.5.2",
|
|
52
|
+
"@univerjs/core": "0.5.2"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"rxjs": "^7.8.1",
|
|
56
56
|
"typescript": "^5.7.2",
|
|
57
|
-
"vite": "^6.0.
|
|
58
|
-
"vitest": "^2.1.
|
|
59
|
-
"@univerjs-infra/shared": "0.5.
|
|
57
|
+
"vite": "^6.0.3",
|
|
58
|
+
"vitest": "^2.1.8",
|
|
59
|
+
"@univerjs-infra/shared": "0.5.2"
|
|
60
60
|
},
|
|
61
61
|
"space": {
|
|
62
62
|
".": {
|