@univerjs/docs 0.16.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +141 -140
- package/lib/index.js +141 -140
- package/lib/types/index.d.ts +1 -1
- package/lib/types/plugin.d.ts +3 -1
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
- /package/lib/types/{controllers/config.schema.d.ts → config/config.d.ts} +0 -0
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var G=Object.defineProperty;var z=(r,i,e)=>i in r?G(r,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[i]=e;var d=(r,i,e)=>z(r,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.getOwnPropertyDescriptor,J=(r,i,e,t)=>{for(var n=t>1?void 0:t?W(i,e):i,s=r.length-1,o;s>=0;s--)(o=r[s])&&(n=o(n)||n);return n},k=(r,i)=>(e,t)=>i(e,t,r);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 o,a;const t=(o=this.getTextRanges(e))!=null?o:[],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: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: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:o,segmentId:a,style:l,isEditing:_,ranges:f})}dispose(){this._textSelection$.complete(),this._refreshSelection$.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:l}=e;this._refreshSelection$.next({unitId:a,subUnitId:l,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})}};exports.DocSelectionManagerService=J([k(0,c.ICommandService),k(1,c.IUniverInstanceService)],exports.DocSelectionManagerService);var Y=Object.getOwnPropertyDescriptor,K=(r,i,e,t)=>{for(var n=t>1?void 0:t?Y(i,e):i,s=r.length-1,o;s>=0;s--)(o=r[s])&&(n=o(n)||n);return n},V=(r,i)=>(e,t)=>i(e,t,r);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=K([V(1,c.Inject(c.LocaleService)),V(2,c.IUniverInstanceService)],exports.DocSkeletonManagerService);class b 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 j="doc.mutation.rich-text-editing",x={id:j,type:c.CommandType.MUTATION,handler:(r,i)=>{var P,B;const{unitId:e,segmentId:t="",actions:n,textRanges:s,prevTextRanges:o,trigger:a,noHistory:l,isCompositionEnd:u,noNeedSetTextRange:g,debounce:_,isEditing:f=!0,isSync:h,syncer:S}=i,m=r.get(c.IUniverInstanceService),p=r.get(D.IRenderManagerService),R=r.get(b),I=m.getUniverDocInstance(e),E=(P=p.getRenderById(e))==null?void 0:P.with(exports.DocSkeletonManagerService).getViewModel();if(I==null||E==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const N=r.get(exports.DocSelectionManagerService),T=(B=N.getDocRanges())!=null?B:[],F=!!I.getSnapshot().disabled;if(c.JSONX.isNoop(n)||n&&n.length===0||F)return{unitId:e,actions:[],textRanges:T};const $=c.JSONX.invertWithDoc(n,I.getSnapshot());I.apply(n),E.reset(I),!g&&s&&a!=null&&!h&&queueMicrotask(()=>{N.replaceDocRanges(s,{unitId:e,subUnitId:e},f,i.options)});const L={commandId:j,unitId:e,segmentId:t,trigger:a,noHistory:l,debounce:_,redoState:{actions:n,textRanges:s},undoState:{actions:$,textRanges:o!=null?o:T},isCompositionEnd:u,isSync:h,syncer:S};return R.emitStateChangeInfo(L),{unitId:e,actions:$,textRanges:T}}},q={id:"doc.mutation.rename-doc",type:c.CommandType.MUTATION,handler:(r,i)=>{const t=r.get(c.IUniverInstanceService).getUnit(i.unitId,c.UniverInstanceType.UNIVER_DOC);return t?(t.setName(i.name),!0):!1}},H="docs.config",A={};var Q=Object.getOwnPropertyDescriptor,Z=(r,i,e,t)=>{for(var n=t>1?void 0:t?Q(i,e):i,s=r.length-1,o;s>=0;s--)(o=r[s])&&(n=o(n)||n);return n},y=(r,i)=>(e,t)=>i(e,t,r);let M=class extends c.Disposable{constructor(r,i,e){super(),this._commandService=r,this._textSelectionManagerService=i,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(r,i){var o;const{startOffset:e,endOffset:t,collapsed:n}=i,s=(o=r.getCustomRanges())==null?void 0:o.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(r=>{if(r.id===C.id){const i=r.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,l)=>t[l]!==a)&&this._textSelectionManagerService.replaceTextRanges(o,n)}}))}};M=Z([y(0,c.ICommandService),y(1,c.Inject(exports.DocSelectionManagerService)),y(2,c.IUniverInstanceService)],M);var ee=Object.getOwnPropertyDescriptor,te=(r,i,e,t)=>{for(var n=t>1?void 0:t?ee(i,e):i,s=r.length-1,o;s>=0;s--)(o=r[s])&&(n=o(n)||n);return n},X=(r,i)=>(e,t)=>i(e,t,r);const ne="DOCS_PLUGIN";var U;exports.UniverDocsPlugin=(U=class extends c.Plugin{constructor(i=A,e,t){super(),this._config=i,this._injector=e,this._configService=t;const{...n}=c.merge({},A,this._config);this._configService.setConfig(H,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[x,q,C].forEach(i=>{this._injector.get(c.ICommandService).registerCommand(i)})}_initializeDependencies(){[[exports.DocSelectionManagerService],[b],[M]].forEach(i=>this._injector.add(i))}onReady(){this._injector.get(M)}},d(U,"pluginName",ne),U);exports.UniverDocsPlugin=te([X(1,c.Inject(c.Injector)),X(2,c.IConfigService)],exports.UniverDocsPlugin);const ie=c.createInterceptorKey("CUSTOM_RANGE"),se=c.createInterceptorKey("CUSTOM_DECORATION"),O={CUSTOM_RANGE:ie,CUSTOM_DECORATION:se};var re=Object.getOwnPropertyDescriptor,oe=(r,i,e,t)=>{for(var n=t>1?void 0:t?re(i,e):i,s=r.length-1,o;s>=0;s--)(o=r[s])&&(n=o(n)||n);return n},ce=(r,i)=>(e,t)=>i(e,t,r);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(O.CUSTOM_RANGE,{priority:-1,handler:(a,l,u)=>u(a)}));let o=new c.DisposableCollection;n.segmentViewModels$.subscribe(a=>{o.dispose(),o=new c.DisposableCollection,a.forEach(l=>{o.add(this.interceptDocumentViewModel(l))})}),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 l,u;return((l=a.priority)!=null?l:0)-((u=o.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(O.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(O.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(s=e.getDataModel().getCustomDecorations())!=null?s:[]})}})),t}};exports.DocInterceptorService=oe([ce(1,c.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);function w(r,i=""){if(!i)return["body"];const{headers:e,footers:t}=r.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 ae(r,i,e){const{unitId:t,segmentId:n}=i,o=r.get(c.IUniverInstanceService).getUnit(t);if(!o)return!1;const a={id:x.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(o,n);return a.params.actions=l.editOp(u.serialize(),g),a}function le(r,i){var I;const{rangeId:e,rangeType:t,wholeEntity:n,properties:s,unitId:o,selections:a}=i,l=r.get(exports.DocSelectionManagerService),u=r.get(c.IUniverInstanceService),g=a!=null?a:l.getTextRanges({unitId:o,subUnitId:o}),_=(I=g==null?void 0:g[0])==null?void 0:I.segmentId;if(!(g!=null&&g.length))return!1;const f=u.getUnit(o,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:x.id,params:{unitId:o,actions:[],textRanges:S.selections,segmentId:_},textX:S},R=w(f,_);return p.params.actions=m.editOp(S.serialize(),R),p}function ue(r,i){const{unitId:e,segmentId:t,insert:n}=i,o=r.get(c.IUniverInstanceService).getUnit(e);if(!o)return!1;const a={id:x.id,params:{unitId:i.unitId,actions:[],textRanges:void 0,segmentId:t}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:i.rangeId,insert:n,segmentId:t});if(!u)return!1;const g=w(o,t);return a.params.actions=l.editOp(u.serialize(),g),a.params.textRanges=u.selections,a}function de(r,i){var S,m,p,R;const{unitId:e,body:t,doc:n}=i;let s=n;if(s||(s=r.get(c.IUniverInstanceService).getUnit(e)),!s)return!1;const o=(S=i.selection)==null?void 0:S.segmentId,a=(m=s.getSelfOrHeaderFooterModel(o))==null?void 0:m.getBody();if(!a)return!1;const l=r.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:o}],_=c.BuildTextUtils.selection.replace({selection:u,body:t,doc:s});if(!_)return!1;const f={id:x.id,params:{unitId:e,actions:[],textRanges:g,debounce:!0,segmentId:o},textX:_},h=c.JSONX.getInstance();return f.params.actions=h.editOp(_.serialize()),f}exports.DOC_INTERCEPTOR_POINT=O;exports.DocStateEmitService=b;exports.RichTextEditingMutation=x;exports.SetTextSelectionsOperation=C;exports.addCustomRangeBySelectionFactory=le;exports.addCustomRangeFactory=ae;exports.deleteCustomRangeFactory=ue;exports.replaceSelectionFactory=de;
|
|
1
|
+
"use strict";var G=Object.defineProperty;var W=(r,s,e)=>s in r?G(r,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[s]=e;var d=(r,s,e)=>W(r,typeof s!="symbol"?s+"":s,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),C=require("@univerjs/engine-render"),v=require("rxjs"),T={id:"doc.operation.set-selections",type:c.CommandType.OPERATION,handler:()=>!0};var J=Object.getOwnPropertyDescriptor,Y=(r,s,e,t)=>{for(var n=t>1?void 0:t?J(s,e):s,i=r.length-1,o;i>=0;i--)(o=r[i])&&(n=o(n)||n);return n},k=(r,s)=>(e,t)=>s(e,t,r);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 o,a;const t=(o=this.getTextRanges(e))!=null?o:[],n=(a=this.getRectRanges(e))!=null?a:[];return[...t,...n].filter(l=>l.startOffset!=null&&l.endOffset!=null).sort((l,u)=>l.startOffset>u.startOffset?1:l.startOffset<u.startOffset?-1:0)}getActiveTextRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t}=e;return t.find(n=>n.isActive)}getActiveRectRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{rectRanges:t}=e;return t.find(n=>n.isActive)}__TEST_ONLY_add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:"",segmentPage:-1,isEditing:t,style:C.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,i){if(t==null)return;const{unitId:o,subUnitId:a}=t;this._refreshSelection$.next({unitId:o,subUnitId:a,docRanges:e,isEditing:n,options:i})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;const n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:i,subUnitId:o,segmentId:a,style:l,textRanges:u,rectRanges:g,isEditing:S}=n,f=[...u,...g].filter(h=>h.startOffset!=null&&h.endOffset!=null).sort((h,_)=>h.startOffset>_.startOffset?1:h.startOffset<_.startOffset?-1:0);this._commandService.executeCommand(T.id,{unitId:i,subUnitId:o,segmentId:a,style:l,isEditing:S,ranges:f})}dispose(){this._textSelection$.complete(),this._refreshSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_getTextRanges(e){var i;if(e==null)return;const{unitId:t,subUnitId:n=""}=e;return(i=this._textSelectionInfo.get(t))==null?void 0:i.get(n)}_refresh(e){const t=this._getTextRanges(e);if(t==null)return;const{textRanges:n,rectRanges:i}=t,o=[...n,...i],{unitId:a,subUnitId:l}=e;this._refreshSelection$.next({unitId:a,subUnitId:l,docRanges:o,isEditing:!1})}_replaceByParam(e){const{unitId:t,subUnitId:n,...i}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...i})}_addByParam(e){const{unitId:t,subUnitId:n,...i}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const o=this._textSelectionInfo.get(t);o.has(n)?o.get(n).textRanges.push(...e.textRanges):o.set(n,{...i})}};exports.DocSelectionManagerService=Y([k(0,c.ICommandService),k(1,c.IUniverInstanceService)],exports.DocSelectionManagerService);var K=Object.getOwnPropertyDescriptor,q=(r,s,e,t)=>{for(var n=t>1?void 0:t?K(s,e):s,i=r.length-1,o;i>=0;i--)(o=r[i])&&(n=o(n)||n);return n},V=(r,s)=>(e,t)=>s(e,t,r);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(i=>{i&&i.getUnitId()===this._context.unitId&&this._update(i)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const e=this._context.unit;this._update(e)}_update(e){const t=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&c.isInternalEditorID(t)?(this._docViewModel.reset(e),this._context.unit=e):this._docViewModel||(this._docViewModel=this._buildDocViewModel(e)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));const n=this._skeleton;n.calculate(),this._currentSkeletonBefore$.next(n),this._currentSkeleton$.next(n),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return C.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new C.DocumentViewModel(e)}};exports.DocSkeletonManagerService=q([V(1,c.Inject(c.LocaleService)),V(2,c.IUniverInstanceService)],exports.DocSkeletonManagerService);class b 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 j="doc.mutation.rich-text-editing",x={id:j,type:c.CommandType.MUTATION,handler:(r,s)=>{var P,B;const{unitId:e,segmentId:t="",actions:n,textRanges:i,prevTextRanges:o,trigger:a,noHistory:l,isCompositionEnd:u,noNeedSetTextRange:g,debounce:S,isEditing:f=!0,isSync:h,syncer:_}=s,m=r.get(c.IUniverInstanceService),p=r.get(C.IRenderManagerService),R=r.get(b),I=m.getUniverDocInstance(e),E=(P=p.getRenderById(e))==null?void 0:P.with(exports.DocSkeletonManagerService).getViewModel();if(I==null||E==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const N=r.get(exports.DocSelectionManagerService),y=(B=N.getDocRanges())!=null?B:[],L=!!I.getSnapshot().disabled;if(c.JSONX.isNoop(n)||n&&n.length===0||L)return{unitId:e,actions:[],textRanges:y};const $=c.JSONX.invertWithDoc(n,I.getSnapshot());I.apply(n),E.reset(I),!g&&i&&a!=null&&!h&&queueMicrotask(()=>{N.replaceDocRanges(i,{unitId:e,subUnitId:e},f,s.options)});const z={commandId:j,unitId:e,segmentId:t,trigger:a,noHistory:l,debounce:S,redoState:{actions:n,textRanges:i},undoState:{actions:$,textRanges:o!=null?o:y},isCompositionEnd:u,isSync:h,syncer:_};return R.emitStateChangeInfo(z),{unitId:e,actions:$,textRanges:y}}},H="@univerjs/docs",Q="0.17.0",A={name:H,version:Q},Z={id:"doc.mutation.rename-doc",type:c.CommandType.MUTATION,handler:(r,s)=>{const t=r.get(c.IUniverInstanceService).getUnit(s.unitId,c.UniverInstanceType.UNIVER_DOC);return t?(t.setName(s.name),!0):!1}},ee="docs.config",X={};var te=Object.getOwnPropertyDescriptor,ne=(r,s,e,t)=>{for(var n=t>1?void 0:t?te(s,e):s,i=r.length-1,o;i>=0;i--)(o=r[i])&&(n=o(n)||n);return n},U=(r,s)=>(e,t)=>s(e,t,r);let M=class extends c.Disposable{constructor(r,s,e){super(),this._commandService=r,this._textSelectionManagerService=s,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(r,s){var o;const{startOffset:e,endOffset:t,collapsed:n}=s,i=(o=r.getCustomRanges())==null?void 0:o.filter(a=>!a.wholeEntity||e<=a.startIndex&&t>a.endIndex?!1:n?a.startIndex<e&&a.endIndex>=t:c.BuildTextUtils.range.isIntersects(e,t-1,a.startIndex,a.endIndex));if(i!=null&&i.length){let a=e,l=t;return i.forEach(u=>{a=Math.min(u.startIndex,a),l=Math.max(u.endIndex+1,l)}),{...s,startOffset:a,endOffset:l,collapsed:a===l}}return s}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===T.id){const s=r.params,{unitId:e,ranges:t,isEditing:n}=s,i=this._univerInstanceService.getUnit(e);if(!i)return;const o=t.map(a=>this._transformCustomRange(i,a));o.some((a,l)=>t[l]!==a)&&this._textSelectionManagerService.replaceTextRanges(o,n)}}))}};M=ne([U(0,c.ICommandService),U(1,c.Inject(exports.DocSelectionManagerService)),U(2,c.IUniverInstanceService)],M);var se=Object.getOwnPropertyDescriptor,ie=(r,s,e,t)=>{for(var n=t>1?void 0:t?se(s,e):s,i=r.length-1,o;i>=0;i--)(o=r[i])&&(n=o(n)||n);return n},F=(r,s)=>(e,t)=>s(e,t,r),O;exports.UniverDocsPlugin=(O=class extends c.Plugin{constructor(s=X,e,t){super(),this._config=s,this._injector=e,this._configService=t;const{...n}=c.merge({},X,this._config);this._configService.setConfig(ee,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[x,Z,T].forEach(s=>{this._injector.get(c.ICommandService).registerCommand(s)})}_initializeDependencies(){[[exports.DocSelectionManagerService],[b],[M]].forEach(s=>this._injector.add(s))}onReady(){this._injector.get(M)}},d(O,"pluginName","DOCS_PLUGIN"),d(O,"packageName",A.name),d(O,"version",A.version),O);exports.UniverDocsPlugin=ie([F(1,c.Inject(c.Injector)),F(2,c.IConfigService)],exports.UniverDocsPlugin);const re=c.createInterceptorKey("CUSTOM_RANGE"),oe=c.createInterceptorKey("CUSTOM_DECORATION"),D={CUSTOM_RANGE:re,CUSTOM_DECORATION:oe};var ce=Object.getOwnPropertyDescriptor,ae=(r,s,e,t)=>{for(var n=t>1?void 0:t?ce(s,e):s,i=r.length-1,o;i>=0;i--)(o=r[i])&&(n=o(n)||n);return n},le=(r,s)=>(e,t)=>s(e,t,r);exports.DocInterceptorService=class extends c.Disposable{constructor(e,t){super();d(this,"_interceptorsByName",new Map);this._context=e,this._docSkeletonManagerService=t;const n=this._docSkeletonManagerService.getViewModel(),i=n.getDataModel().getUnitId();if(i===c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(n)),this.disposeWithMe(this.intercept(D.CUSTOM_RANGE,{priority:-1,handler:(a,l,u)=>u(a)}));let o=new c.DisposableCollection;n.segmentViewModels$.subscribe(a=>{o.dispose(),o=new c.DisposableCollection,a.forEach(l=>{o.add(this.interceptDocumentViewModel(l))})}),this.disposeWithMe(o)}intercept(e,t){const n=e;this._interceptorsByName.has(n)||this._interceptorsByName.set(n,[]);const i=this._interceptorsByName.get(n);return i.push(t),this._interceptorsByName.set(n,i.sort((o,a)=>{var l,u;return((l=a.priority)!=null?l:0)-((u=o.priority)!=null?u:0)})),this.disposeWithMe(c.toDisposable(()=>c.remove(this._interceptorsByName.get(n),t)))}fetchThroughInterceptors(e){const t=e,n=this._interceptorsByName.get(t);return c.composeInterceptors(n||[])}interceptDocumentViewModel(e){const t=new c.DisposableCollection;return t.add(e.registerCustomRangeInterceptor({getCustomRange:n=>{var i;return this.fetchThroughInterceptors(D.CUSTOM_RANGE)(e.getCustomRangeRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customRanges:(i=e.getDataModel().getCustomRanges())!=null?i:[]})},getCustomDecoration:n=>{var i;return this.fetchThroughInterceptors(D.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(i=e.getDataModel().getCustomDecorations())!=null?i:[]})}})),t}};exports.DocInterceptorService=ae([le(1,c.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);function w(r,s=""){if(!s)return["body"];const{headers:e,footers:t}=r.getSnapshot();if(e==null&&t==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[s])!=null)return["headers",s,"body"];if((t==null?void 0:t[s])!=null)return["footers",s,"body"];throw new Error("Segment id not found in headers or footers")}function ue(r,s,e){const{unitId:t,segmentId:n}=s,o=r.get(c.IUniverInstanceService).getUnit(t);if(!o)return!1;const a={id:x.id,params:{unitId:s.unitId,actions:[],textRanges:void 0}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.add({...s,body:e});if(!u)return!1;const g=w(o,n);return a.params.actions=l.editOp(u.serialize(),g),a}function de(r,s){var I;const{rangeId:e,rangeType:t,wholeEntity:n,properties:i,unitId:o,selections:a}=s,l=r.get(exports.DocSelectionManagerService),u=r.get(c.IUniverInstanceService),g=a!=null?a:l.getTextRanges({unitId:o,subUnitId:o}),S=(I=g==null?void 0:g[0])==null?void 0:I.segmentId;if(!(g!=null&&g.length))return!1;const f=u.getUnit(o,c.UniverInstanceType.UNIVER_DOC);if(!f)return!1;const h=f.getSelfOrHeaderFooterModel(S).getBody();if(!h)return!1;const _=c.BuildTextUtils.customRange.add({ranges:g,rangeId:e,rangeType:t,segmentId:S,wholeEntity:n,properties:i,body:h});if(!_)return!1;const m=c.JSONX.getInstance(),p={id:x.id,params:{unitId:o,actions:[],textRanges:_.selections,segmentId:S},textX:_},R=w(f,S);return p.params.actions=m.editOp(_.serialize(),R),p}function ge(r,s){const{unitId:e,segmentId:t,insert:n}=s,o=r.get(c.IUniverInstanceService).getUnit(e);if(!o)return!1;const a={id:x.id,params:{unitId:s.unitId,actions:[],textRanges:void 0,segmentId:t}},l=c.JSONX.getInstance(),u=c.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:s.rangeId,insert:n,segmentId:t});if(!u)return!1;const g=w(o,t);return a.params.actions=l.editOp(u.serialize(),g),a.params.textRanges=u.selections,a}function he(r,s){var _,m,p,R;const{unitId:e,body:t,doc:n}=s;let i=n;if(i||(i=r.get(c.IUniverInstanceService).getUnit(e)),!i)return!1;const o=(_=s.selection)==null?void 0:_.segmentId,a=(m=i.getSelfOrHeaderFooterModel(o))==null?void 0:m.getBody();if(!a)return!1;const l=r.get(exports.DocSelectionManagerService),u=(p=s.selection)!=null?p:l.getActiveTextRange();if(!u||!a)return!1;const g=(R=s.textRanges)!=null?R:[{startOffset:u.startOffset+t.dataStream.length,endOffset:u.startOffset+t.dataStream.length,collapsed:!0,segmentId:o}],S=c.BuildTextUtils.selection.replace({selection:u,body:t,doc:i});if(!S)return!1;const f={id:x.id,params:{unitId:e,actions:[],textRanges:g,debounce:!0,segmentId:o},textX:S},h=c.JSONX.getInstance();return f.params.actions=h.editOp(S.serialize()),f}exports.DOC_INTERCEPTOR_POINT=D;exports.DocStateEmitService=b;exports.RichTextEditingMutation=x;exports.SetTextSelectionsOperation=T;exports.addCustomRangeBySelectionFactory=de;exports.addCustomRangeFactory=ue;exports.deleteCustomRangeFactory=ge;exports.replaceSelectionFactory=he;
|
package/lib/es/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { CommandType as P, RxDisposable as V, UniverInstanceType as
|
|
5
|
-
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as
|
|
6
|
-
import { Subject as
|
|
1
|
+
var re = Object.defineProperty;
|
|
2
|
+
var oe = (i, e, t) => e in i ? re(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var l = (i, e, t) => oe(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { CommandType as P, RxDisposable as V, UniverInstanceType as w, ICommandService as B, IUniverInstanceService as I, Inject as b, LocaleService as ce, isInternalEditorID as ae, JSONX as x, Disposable as Z, BuildTextUtils as D, Injector as le, IConfigService as ue, Plugin as de, merge as ge, createInterceptorKey as ee, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as he, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as _e, DisposableCollection as $, toDisposable as fe, remove as Se, composeInterceptors as Ie } from "@univerjs/core";
|
|
5
|
+
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as pe, DocumentSkeleton as me, DocumentViewModel as ve, IRenderManagerService as Re } from "@univerjs/engine-render";
|
|
6
|
+
import { Subject as xe, BehaviorSubject as C, takeUntil as te } from "rxjs";
|
|
7
7
|
const k = {
|
|
8
8
|
id: "doc.operation.set-selections",
|
|
9
9
|
type: P.OPERATION,
|
|
10
10
|
handler: () => !0
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
12
|
+
var Oe = Object.getOwnPropertyDescriptor, Ce = (i, e, t, n) => {
|
|
13
|
+
for (var s = n > 1 ? void 0 : n ? Oe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
14
14
|
(o = i[r]) && (s = o(s) || s);
|
|
15
15
|
return s;
|
|
16
|
-
},
|
|
16
|
+
}, G = (i, e) => (t, n) => e(t, n, i);
|
|
17
17
|
let m = class extends V {
|
|
18
18
|
constructor(e, t) {
|
|
19
19
|
super();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
l(this, "_currentSelection", null);
|
|
21
|
+
l(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
|
|
22
|
+
l(this, "_textSelection$", new xe());
|
|
23
|
+
l(this, "textSelection$", this._textSelection$.asObservable());
|
|
24
|
+
l(this, "_refreshSelection$", new C(null));
|
|
25
|
+
l(this, "refreshSelection$", this._refreshSelection$.asObservable());
|
|
26
26
|
this._commandService = e, this._univerInstanceService = t, this._listenCurrentUnit();
|
|
27
27
|
}
|
|
28
28
|
_listenCurrentUnit() {
|
|
29
|
-
this._univerInstanceService.getCurrentTypeOfUnit$(
|
|
29
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(w.UNIVER_DOC).pipe(te(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,7 +126,7 @@ 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:
|
|
129
|
+
const { unitId: s, subUnitId: r, segmentId: o, style: c, textRanges: a, rectRanges: u, isEditing: d } = n, h = [...a, ...u].filter((g) => g.startOffset != null && g.endOffset != null).sort((g, _) => g.startOffset > _.startOffset ? 1 : g.startOffset < _.startOffset ? -1 : 0);
|
|
130
130
|
this._commandService.executeCommand(k.id, {
|
|
131
131
|
unitId: s,
|
|
132
132
|
subUnitId: r,
|
|
@@ -172,28 +172,28 @@ 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 =
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
m = Ce([
|
|
176
|
+
G(0, B),
|
|
177
|
+
G(1, I)
|
|
178
178
|
], m);
|
|
179
|
-
var
|
|
180
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
179
|
+
var De = Object.getOwnPropertyDescriptor, Me = (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 = o(s) || s);
|
|
182
182
|
return s;
|
|
183
183
|
}, W = (i, e) => (t, n) => e(t, n, i);
|
|
184
|
-
let
|
|
184
|
+
let T = class extends V {
|
|
185
185
|
constructor(e, t, n) {
|
|
186
186
|
super();
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
l(this, "_skeleton");
|
|
188
|
+
l(this, "_docViewModel");
|
|
189
|
+
l(this, "_currentSkeleton$", new C(null));
|
|
190
|
+
l(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
|
|
191
191
|
// CurrentSkeletonBefore for pre-triggered logic during registration
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(
|
|
192
|
+
l(this, "_currentSkeletonBefore$", new C(null));
|
|
193
|
+
l(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
|
|
194
|
+
l(this, "_currentViewModel$", new C(null));
|
|
195
|
+
l(this, "currentViewModel$", this._currentViewModel$.asObservable());
|
|
196
|
+
this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(w.UNIVER_DOC).pipe(te(this.dispose$)).subscribe((s) => {
|
|
197
197
|
s && s.getUnitId() === this._context.unitId && this._update(s);
|
|
198
198
|
});
|
|
199
199
|
}
|
|
@@ -214,26 +214,26 @@ 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 && ae(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 me.create(e, this._localeService);
|
|
223
223
|
}
|
|
224
224
|
_buildDocViewModel(e) {
|
|
225
|
-
return new
|
|
225
|
+
return new ve(e);
|
|
226
226
|
}
|
|
227
227
|
};
|
|
228
|
-
|
|
229
|
-
W(1,
|
|
228
|
+
T = Me([
|
|
229
|
+
W(1, b(ce)),
|
|
230
230
|
W(2, I)
|
|
231
|
-
],
|
|
232
|
-
class
|
|
231
|
+
], T);
|
|
232
|
+
class ne extends V {
|
|
233
233
|
constructor() {
|
|
234
234
|
super();
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
l(this, "_docStateChangeParams$", new C(null));
|
|
236
|
+
l(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
|
|
237
237
|
}
|
|
238
238
|
emitStateChangeInfo(t) {
|
|
239
239
|
this._docStateChangeParams$.next(t);
|
|
@@ -247,7 +247,7 @@ const Y = "doc.mutation.rich-text-editing", M = {
|
|
|
247
247
|
type: P.MUTATION,
|
|
248
248
|
// eslint-disable-next-line max-lines-per-function
|
|
249
249
|
handler: (i, e) => {
|
|
250
|
-
var
|
|
250
|
+
var z, F;
|
|
251
251
|
const {
|
|
252
252
|
unitId: t,
|
|
253
253
|
segmentId: n = "",
|
|
@@ -256,27 +256,27 @@ const Y = "doc.mutation.rich-text-editing", M = {
|
|
|
256
256
|
prevTextRanges: o,
|
|
257
257
|
trigger: c,
|
|
258
258
|
noHistory: a,
|
|
259
|
-
isCompositionEnd:
|
|
259
|
+
isCompositionEnd: u,
|
|
260
260
|
noNeedSetTextRange: d,
|
|
261
261
|
debounce: h,
|
|
262
262
|
isEditing: g = !0,
|
|
263
263
|
isSync: _,
|
|
264
264
|
syncer: f
|
|
265
|
-
} = e,
|
|
265
|
+
} = e, v = i.get(I), p = i.get(Re), R = i.get(ne), S = v.getUniverDocInstance(t), j = (z = p.getRenderById(t)) == null ? void 0 : z.with(T).getViewModel();
|
|
266
266
|
if (S == null || j == null)
|
|
267
267
|
throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
|
|
268
|
-
const L = i.get(m),
|
|
269
|
-
if (x.isNoop(s) || s && s.length === 0 ||
|
|
268
|
+
const L = i.get(m), U = (F = L.getDocRanges()) != null ? F : [], se = !!S.getSnapshot().disabled;
|
|
269
|
+
if (x.isNoop(s) || s && s.length === 0 || se)
|
|
270
270
|
return {
|
|
271
271
|
unitId: t,
|
|
272
272
|
actions: [],
|
|
273
|
-
textRanges:
|
|
273
|
+
textRanges: U
|
|
274
274
|
};
|
|
275
275
|
const X = x.invertWithDoc(s, S.getSnapshot());
|
|
276
276
|
S.apply(s), j.reset(S), !d && r && c != null && !_ && queueMicrotask(() => {
|
|
277
277
|
L.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
|
|
278
278
|
});
|
|
279
|
-
const
|
|
279
|
+
const ie = {
|
|
280
280
|
commandId: Y,
|
|
281
281
|
unitId: t,
|
|
282
282
|
segmentId: n,
|
|
@@ -289,42 +289,45 @@ const Y = "doc.mutation.rich-text-editing", M = {
|
|
|
289
289
|
},
|
|
290
290
|
undoState: {
|
|
291
291
|
actions: X,
|
|
292
|
-
textRanges: o != null ? o :
|
|
292
|
+
textRanges: o != null ? o : U
|
|
293
293
|
},
|
|
294
|
-
isCompositionEnd:
|
|
294
|
+
isCompositionEnd: u,
|
|
295
295
|
isSync: _,
|
|
296
296
|
syncer: f
|
|
297
297
|
};
|
|
298
|
-
return
|
|
298
|
+
return R.emitStateChangeInfo(ie), {
|
|
299
299
|
unitId: t,
|
|
300
300
|
actions: X,
|
|
301
|
-
textRanges:
|
|
301
|
+
textRanges: U
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
|
-
},
|
|
304
|
+
}, Te = "@univerjs/docs", ye = "0.17.0", K = {
|
|
305
|
+
name: Te,
|
|
306
|
+
version: ye
|
|
307
|
+
}, we = {
|
|
305
308
|
id: "doc.mutation.rename-doc",
|
|
306
309
|
type: P.MUTATION,
|
|
307
310
|
handler: (i, e) => {
|
|
308
|
-
const n = i.get(I).getUnit(e.unitId,
|
|
311
|
+
const n = i.get(I).getUnit(e.unitId, w.UNIVER_DOC);
|
|
309
312
|
return n ? (n.setName(e.name), !0) : !1;
|
|
310
313
|
}
|
|
311
|
-
},
|
|
312
|
-
var
|
|
313
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
314
|
+
}, be = "docs.config", H = {};
|
|
315
|
+
var Ue = Object.getOwnPropertyDescriptor, $e = (i, e, t, n) => {
|
|
316
|
+
for (var s = n > 1 ? void 0 : n ? Ue(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
314
317
|
(o = i[r]) && (s = o(s) || s);
|
|
315
318
|
return s;
|
|
316
|
-
},
|
|
317
|
-
let
|
|
319
|
+
}, E = (i, e) => (t, n) => e(t, n, i);
|
|
320
|
+
let y = class extends Z {
|
|
318
321
|
constructor(i, e, t) {
|
|
319
322
|
super(), this._commandService = i, this._textSelectionManagerService = e, this._univerInstanceService = t, this._initSelectionChange();
|
|
320
323
|
}
|
|
321
324
|
_transformCustomRange(i, e) {
|
|
322
325
|
var o;
|
|
323
|
-
const { startOffset: t, endOffset: n, collapsed: s } = e, r = (o = i.getCustomRanges()) == null ? void 0 : o.filter((c) => !c.wholeEntity || t <= c.startIndex && n > c.endIndex ? !1 : s ? c.startIndex < t && c.endIndex >= n :
|
|
326
|
+
const { startOffset: t, endOffset: n, collapsed: s } = e, r = (o = i.getCustomRanges()) == null ? void 0 : o.filter((c) => !c.wholeEntity || t <= c.startIndex && n > c.endIndex ? !1 : s ? c.startIndex < t && c.endIndex >= n : D.range.isIntersects(t, n - 1, c.startIndex, c.endIndex));
|
|
324
327
|
if (r != null && r.length) {
|
|
325
328
|
let c = t, a = n;
|
|
326
|
-
return r.forEach((
|
|
327
|
-
c = Math.min(
|
|
329
|
+
return r.forEach((u) => {
|
|
330
|
+
c = Math.min(u.startIndex, c), a = Math.max(u.endIndex + 1, a);
|
|
328
331
|
}), {
|
|
329
332
|
...e,
|
|
330
333
|
startOffset: c,
|
|
@@ -346,28 +349,26 @@ let T = class extends Q {
|
|
|
346
349
|
}));
|
|
347
350
|
}
|
|
348
351
|
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
],
|
|
354
|
-
var
|
|
355
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
352
|
+
y = $e([
|
|
353
|
+
E(0, B),
|
|
354
|
+
E(1, b(m)),
|
|
355
|
+
E(2, I)
|
|
356
|
+
], y);
|
|
357
|
+
var Ee = Object.getOwnPropertyDescriptor, Ne = (i, e, t, n) => {
|
|
358
|
+
for (var s = n > 1 ? void 0 : n ? Ee(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
356
359
|
(o = i[r]) && (s = o(s) || s);
|
|
357
360
|
return s;
|
|
358
|
-
},
|
|
359
|
-
|
|
360
|
-
var N;
|
|
361
|
-
let q = (N = class extends ue {
|
|
361
|
+
}, q = (i, e) => (t, n) => e(t, n, i), O;
|
|
362
|
+
let J = (O = class extends de {
|
|
362
363
|
// static override type = UniverInstanceType.UNIVER_DOC;
|
|
363
|
-
constructor(i =
|
|
364
|
+
constructor(i = H, e, t) {
|
|
364
365
|
super(), this._config = i, this._injector = e, this._configService = t;
|
|
365
|
-
const { ...n } =
|
|
366
|
+
const { ...n } = ge(
|
|
366
367
|
{},
|
|
367
|
-
|
|
368
|
+
H,
|
|
368
369
|
this._config
|
|
369
370
|
);
|
|
370
|
-
this._configService.setConfig(
|
|
371
|
+
this._configService.setConfig(be, n);
|
|
371
372
|
}
|
|
372
373
|
onStarting() {
|
|
373
374
|
this._initializeDependencies(), this._initializeCommands();
|
|
@@ -375,7 +376,7 @@ let q = (N = class extends ue {
|
|
|
375
376
|
_initializeCommands() {
|
|
376
377
|
[
|
|
377
378
|
M,
|
|
378
|
-
|
|
379
|
+
we,
|
|
379
380
|
k
|
|
380
381
|
].forEach((i) => {
|
|
381
382
|
this._injector.get(B).registerCommand(i);
|
|
@@ -384,42 +385,42 @@ let q = (N = class extends ue {
|
|
|
384
385
|
_initializeDependencies() {
|
|
385
386
|
[
|
|
386
387
|
[m],
|
|
387
|
-
[
|
|
388
|
-
[
|
|
388
|
+
[ne],
|
|
389
|
+
[y]
|
|
389
390
|
].forEach((i) => this._injector.add(i));
|
|
390
391
|
}
|
|
391
392
|
onReady() {
|
|
392
|
-
this._injector.get(
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
],
|
|
399
|
-
const
|
|
400
|
-
CUSTOM_RANGE:
|
|
401
|
-
CUSTOM_DECORATION:
|
|
393
|
+
this._injector.get(y);
|
|
394
|
+
}
|
|
395
|
+
}, l(O, "pluginName", "DOCS_PLUGIN"), l(O, "packageName", K.name), l(O, "version", K.version), O);
|
|
396
|
+
J = Ne([
|
|
397
|
+
q(1, b(le)),
|
|
398
|
+
q(2, ue)
|
|
399
|
+
], J);
|
|
400
|
+
const Pe = ee("CUSTOM_RANGE"), Ve = ee("CUSTOM_DECORATION"), N = {
|
|
401
|
+
CUSTOM_RANGE: Pe,
|
|
402
|
+
CUSTOM_DECORATION: Ve
|
|
402
403
|
};
|
|
403
|
-
var
|
|
404
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
404
|
+
var Be = Object.getOwnPropertyDescriptor, ke = (i, e, t, n) => {
|
|
405
|
+
for (var s = n > 1 ? void 0 : n ? Be(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
405
406
|
(o = i[r]) && (s = o(s) || s);
|
|
406
407
|
return s;
|
|
407
|
-
},
|
|
408
|
-
let
|
|
408
|
+
}, Ae = (i, e) => (t, n) => e(t, n, i);
|
|
409
|
+
let Q = class extends Z {
|
|
409
410
|
constructor(e, t) {
|
|
410
411
|
super();
|
|
411
|
-
|
|
412
|
+
l(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
412
413
|
this._context = e, this._docSkeletonManagerService = t;
|
|
413
414
|
const n = this._docSkeletonManagerService.getViewModel(), s = n.getDataModel().getUnitId();
|
|
414
|
-
if (s ===
|
|
415
|
+
if (s === he || s === _e)
|
|
415
416
|
return;
|
|
416
|
-
this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(
|
|
417
|
+
this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(N.CUSTOM_RANGE, {
|
|
417
418
|
priority: -1,
|
|
418
419
|
handler: (o, c, a) => a(o)
|
|
419
420
|
}));
|
|
420
|
-
let r = new
|
|
421
|
+
let r = new $();
|
|
421
422
|
n.segmentViewModels$.subscribe((o) => {
|
|
422
|
-
r.dispose(), r = new
|
|
423
|
+
r.dispose(), r = new $(), o.forEach((c) => {
|
|
423
424
|
r.add(this.interceptDocumentViewModel(c));
|
|
424
425
|
});
|
|
425
426
|
}), this.disposeWithMe(r);
|
|
@@ -434,18 +435,18 @@ let J = class extends Q {
|
|
|
434
435
|
var c, a;
|
|
435
436
|
return ((c = o.priority) != null ? c : 0) - ((a = r.priority) != null ? a : 0);
|
|
436
437
|
})
|
|
437
|
-
), this.disposeWithMe(
|
|
438
|
+
), this.disposeWithMe(fe(() => Se(this._interceptorsByName.get(n), t)));
|
|
438
439
|
}
|
|
439
440
|
fetchThroughInterceptors(e) {
|
|
440
441
|
const t = e, n = this._interceptorsByName.get(t);
|
|
441
|
-
return
|
|
442
|
+
return Ie(n || []);
|
|
442
443
|
}
|
|
443
444
|
interceptDocumentViewModel(e) {
|
|
444
|
-
const t = new
|
|
445
|
+
const t = new $();
|
|
445
446
|
return t.add(e.registerCustomRangeInterceptor({
|
|
446
447
|
getCustomRange: (n) => {
|
|
447
448
|
var s;
|
|
448
|
-
return this.fetchThroughInterceptors(
|
|
449
|
+
return this.fetchThroughInterceptors(N.CUSTOM_RANGE)(
|
|
449
450
|
e.getCustomRangeRaw(n),
|
|
450
451
|
{
|
|
451
452
|
index: n,
|
|
@@ -456,7 +457,7 @@ let J = class extends Q {
|
|
|
456
457
|
},
|
|
457
458
|
getCustomDecoration: (n) => {
|
|
458
459
|
var s;
|
|
459
|
-
return this.fetchThroughInterceptors(
|
|
460
|
+
return this.fetchThroughInterceptors(N.CUSTOM_DECORATION)(
|
|
460
461
|
e.getCustomDecorationRaw(n),
|
|
461
462
|
{
|
|
462
463
|
index: n,
|
|
@@ -468,9 +469,9 @@ let J = class extends Q {
|
|
|
468
469
|
})), t;
|
|
469
470
|
}
|
|
470
471
|
};
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
],
|
|
472
|
+
Q = ke([
|
|
473
|
+
Ae(1, b(T))
|
|
474
|
+
], Q);
|
|
474
475
|
function A(i, e = "") {
|
|
475
476
|
if (!e)
|
|
476
477
|
return ["body"];
|
|
@@ -483,7 +484,7 @@ function A(i, e = "") {
|
|
|
483
484
|
return ["footers", e, "body"];
|
|
484
485
|
throw new Error("Segment id not found in headers or footers");
|
|
485
486
|
}
|
|
486
|
-
function
|
|
487
|
+
function Fe(i, e, t) {
|
|
487
488
|
const { unitId: n, segmentId: s } = e, o = i.get(I).getUnit(n);
|
|
488
489
|
if (!o)
|
|
489
490
|
return !1;
|
|
@@ -494,24 +495,24 @@ function Xe(i, e, t) {
|
|
|
494
495
|
actions: [],
|
|
495
496
|
textRanges: void 0
|
|
496
497
|
}
|
|
497
|
-
}, a = x.getInstance(),
|
|
498
|
-
if (!
|
|
498
|
+
}, a = x.getInstance(), u = D.customRange.add({ ...e, body: t });
|
|
499
|
+
if (!u)
|
|
499
500
|
return !1;
|
|
500
501
|
const d = A(o, s);
|
|
501
|
-
return c.params.actions = a.editOp(
|
|
502
|
+
return c.params.actions = a.editOp(u.serialize(), d), c;
|
|
502
503
|
}
|
|
503
504
|
function Ge(i, e) {
|
|
504
505
|
var S;
|
|
505
|
-
const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selections: c } = e, a = i.get(m),
|
|
506
|
+
const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selections: c } = e, a = i.get(m), u = i.get(I), d = c != null ? c : a.getTextRanges({ unitId: o, subUnitId: o }), h = (S = d == null ? void 0 : d[0]) == null ? void 0 : S.segmentId;
|
|
506
507
|
if (!(d != null && d.length))
|
|
507
508
|
return !1;
|
|
508
|
-
const g =
|
|
509
|
+
const g = u.getUnit(o, w.UNIVER_DOC);
|
|
509
510
|
if (!g)
|
|
510
511
|
return !1;
|
|
511
512
|
const _ = g.getSelfOrHeaderFooterModel(h).getBody();
|
|
512
513
|
if (!_)
|
|
513
514
|
return !1;
|
|
514
|
-
const f =
|
|
515
|
+
const f = D.customRange.add({
|
|
515
516
|
ranges: d,
|
|
516
517
|
rangeId: t,
|
|
517
518
|
rangeType: n,
|
|
@@ -522,7 +523,7 @@ function Ge(i, e) {
|
|
|
522
523
|
});
|
|
523
524
|
if (!f)
|
|
524
525
|
return !1;
|
|
525
|
-
const
|
|
526
|
+
const v = x.getInstance(), p = {
|
|
526
527
|
id: M.id,
|
|
527
528
|
params: {
|
|
528
529
|
unitId: o,
|
|
@@ -531,10 +532,10 @@ function Ge(i, e) {
|
|
|
531
532
|
segmentId: h
|
|
532
533
|
},
|
|
533
534
|
textX: f
|
|
534
|
-
},
|
|
535
|
-
return p.params.actions =
|
|
535
|
+
}, R = A(g, h);
|
|
536
|
+
return p.params.actions = v.editOp(f.serialize(), R), p;
|
|
536
537
|
}
|
|
537
|
-
function
|
|
538
|
+
function We(i, e) {
|
|
538
539
|
const { unitId: t, segmentId: n, insert: s } = e, o = i.get(I).getUnit(t);
|
|
539
540
|
if (!o)
|
|
540
541
|
return !1;
|
|
@@ -546,35 +547,35 @@ function ze(i, e) {
|
|
|
546
547
|
textRanges: void 0,
|
|
547
548
|
segmentId: n
|
|
548
549
|
}
|
|
549
|
-
}, a = x.getInstance(),
|
|
550
|
+
}, a = x.getInstance(), u = D.customRange.delete({
|
|
550
551
|
documentDataModel: o,
|
|
551
552
|
rangeId: e.rangeId,
|
|
552
553
|
insert: s,
|
|
553
554
|
segmentId: n
|
|
554
555
|
});
|
|
555
|
-
if (!
|
|
556
|
+
if (!u)
|
|
556
557
|
return !1;
|
|
557
558
|
const d = A(o, n);
|
|
558
|
-
return c.params.actions = a.editOp(
|
|
559
|
+
return c.params.actions = a.editOp(u.serialize(), d), c.params.textRanges = u.selections, c;
|
|
559
560
|
}
|
|
560
|
-
function
|
|
561
|
-
var f,
|
|
561
|
+
function Ye(i, e) {
|
|
562
|
+
var f, v, p, R;
|
|
562
563
|
const { unitId: t, body: n, doc: s } = e;
|
|
563
564
|
let r = s;
|
|
564
565
|
if (r || (r = i.get(I).getUnit(t)), !r)
|
|
565
566
|
return !1;
|
|
566
|
-
const o = (f = e.selection) == null ? void 0 : f.segmentId, c = (
|
|
567
|
+
const o = (f = e.selection) == null ? void 0 : f.segmentId, c = (v = r.getSelfOrHeaderFooterModel(o)) == null ? void 0 : v.getBody();
|
|
567
568
|
if (!c) return !1;
|
|
568
|
-
const a = i.get(m),
|
|
569
|
-
if (!
|
|
569
|
+
const a = i.get(m), u = (p = e.selection) != null ? p : a.getActiveTextRange();
|
|
570
|
+
if (!u || !c)
|
|
570
571
|
return !1;
|
|
571
|
-
const d = (
|
|
572
|
-
startOffset:
|
|
573
|
-
endOffset:
|
|
572
|
+
const d = (R = e.textRanges) != null ? R : [{
|
|
573
|
+
startOffset: u.startOffset + n.dataStream.length,
|
|
574
|
+
endOffset: u.startOffset + n.dataStream.length,
|
|
574
575
|
collapsed: !0,
|
|
575
576
|
segmentId: o
|
|
576
|
-
}], h =
|
|
577
|
-
selection:
|
|
577
|
+
}], h = D.selection.replace({
|
|
578
|
+
selection: u,
|
|
578
579
|
body: n,
|
|
579
580
|
doc: r
|
|
580
581
|
});
|
|
@@ -594,16 +595,16 @@ function Fe(i, e) {
|
|
|
594
595
|
return g.params.actions = _.editOp(h.serialize()), g;
|
|
595
596
|
}
|
|
596
597
|
export {
|
|
597
|
-
|
|
598
|
-
|
|
598
|
+
N as DOC_INTERCEPTOR_POINT,
|
|
599
|
+
Q as DocInterceptorService,
|
|
599
600
|
m as DocSelectionManagerService,
|
|
600
|
-
|
|
601
|
-
|
|
601
|
+
T as DocSkeletonManagerService,
|
|
602
|
+
ne as DocStateEmitService,
|
|
602
603
|
M as RichTextEditingMutation,
|
|
603
604
|
k as SetTextSelectionsOperation,
|
|
604
|
-
|
|
605
|
+
J as UniverDocsPlugin,
|
|
605
606
|
Ge as addCustomRangeBySelectionFactory,
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
607
|
+
Fe as addCustomRangeFactory,
|
|
608
|
+
We as deleteCustomRangeFactory,
|
|
609
|
+
Ye as replaceSelectionFactory
|
|
609
610
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { CommandType as P, RxDisposable as V, UniverInstanceType as
|
|
5
|
-
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as
|
|
6
|
-
import { Subject as
|
|
1
|
+
var re = Object.defineProperty;
|
|
2
|
+
var oe = (i, e, t) => e in i ? re(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var l = (i, e, t) => oe(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { CommandType as P, RxDisposable as V, UniverInstanceType as w, ICommandService as B, IUniverInstanceService as I, Inject as b, LocaleService as ce, isInternalEditorID as ae, JSONX as x, Disposable as Z, BuildTextUtils as D, Injector as le, IConfigService as ue, Plugin as de, merge as ge, createInterceptorKey as ee, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as he, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as _e, DisposableCollection as $, toDisposable as fe, remove as Se, composeInterceptors as Ie } from "@univerjs/core";
|
|
5
|
+
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as pe, DocumentSkeleton as me, DocumentViewModel as ve, IRenderManagerService as Re } from "@univerjs/engine-render";
|
|
6
|
+
import { Subject as xe, BehaviorSubject as C, takeUntil as te } from "rxjs";
|
|
7
7
|
const k = {
|
|
8
8
|
id: "doc.operation.set-selections",
|
|
9
9
|
type: P.OPERATION,
|
|
10
10
|
handler: () => !0
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
12
|
+
var Oe = Object.getOwnPropertyDescriptor, Ce = (i, e, t, n) => {
|
|
13
|
+
for (var s = n > 1 ? void 0 : n ? Oe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
14
14
|
(o = i[r]) && (s = o(s) || s);
|
|
15
15
|
return s;
|
|
16
|
-
},
|
|
16
|
+
}, G = (i, e) => (t, n) => e(t, n, i);
|
|
17
17
|
let m = class extends V {
|
|
18
18
|
constructor(e, t) {
|
|
19
19
|
super();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
l(this, "_currentSelection", null);
|
|
21
|
+
l(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
|
|
22
|
+
l(this, "_textSelection$", new xe());
|
|
23
|
+
l(this, "textSelection$", this._textSelection$.asObservable());
|
|
24
|
+
l(this, "_refreshSelection$", new C(null));
|
|
25
|
+
l(this, "refreshSelection$", this._refreshSelection$.asObservable());
|
|
26
26
|
this._commandService = e, this._univerInstanceService = t, this._listenCurrentUnit();
|
|
27
27
|
}
|
|
28
28
|
_listenCurrentUnit() {
|
|
29
|
-
this._univerInstanceService.getCurrentTypeOfUnit$(
|
|
29
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(w.UNIVER_DOC).pipe(te(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,7 +126,7 @@ 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:
|
|
129
|
+
const { unitId: s, subUnitId: r, segmentId: o, style: c, textRanges: a, rectRanges: u, isEditing: d } = n, h = [...a, ...u].filter((g) => g.startOffset != null && g.endOffset != null).sort((g, _) => g.startOffset > _.startOffset ? 1 : g.startOffset < _.startOffset ? -1 : 0);
|
|
130
130
|
this._commandService.executeCommand(k.id, {
|
|
131
131
|
unitId: s,
|
|
132
132
|
subUnitId: r,
|
|
@@ -172,28 +172,28 @@ 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 =
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
m = Ce([
|
|
176
|
+
G(0, B),
|
|
177
|
+
G(1, I)
|
|
178
178
|
], m);
|
|
179
|
-
var
|
|
180
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
179
|
+
var De = Object.getOwnPropertyDescriptor, Me = (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 = o(s) || s);
|
|
182
182
|
return s;
|
|
183
183
|
}, W = (i, e) => (t, n) => e(t, n, i);
|
|
184
|
-
let
|
|
184
|
+
let T = class extends V {
|
|
185
185
|
constructor(e, t, n) {
|
|
186
186
|
super();
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
l(this, "_skeleton");
|
|
188
|
+
l(this, "_docViewModel");
|
|
189
|
+
l(this, "_currentSkeleton$", new C(null));
|
|
190
|
+
l(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
|
|
191
191
|
// CurrentSkeletonBefore for pre-triggered logic during registration
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(
|
|
192
|
+
l(this, "_currentSkeletonBefore$", new C(null));
|
|
193
|
+
l(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
|
|
194
|
+
l(this, "_currentViewModel$", new C(null));
|
|
195
|
+
l(this, "currentViewModel$", this._currentViewModel$.asObservable());
|
|
196
|
+
this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(w.UNIVER_DOC).pipe(te(this.dispose$)).subscribe((s) => {
|
|
197
197
|
s && s.getUnitId() === this._context.unitId && this._update(s);
|
|
198
198
|
});
|
|
199
199
|
}
|
|
@@ -214,26 +214,26 @@ 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 && ae(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 me.create(e, this._localeService);
|
|
223
223
|
}
|
|
224
224
|
_buildDocViewModel(e) {
|
|
225
|
-
return new
|
|
225
|
+
return new ve(e);
|
|
226
226
|
}
|
|
227
227
|
};
|
|
228
|
-
|
|
229
|
-
W(1,
|
|
228
|
+
T = Me([
|
|
229
|
+
W(1, b(ce)),
|
|
230
230
|
W(2, I)
|
|
231
|
-
],
|
|
232
|
-
class
|
|
231
|
+
], T);
|
|
232
|
+
class ne extends V {
|
|
233
233
|
constructor() {
|
|
234
234
|
super();
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
l(this, "_docStateChangeParams$", new C(null));
|
|
236
|
+
l(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
|
|
237
237
|
}
|
|
238
238
|
emitStateChangeInfo(t) {
|
|
239
239
|
this._docStateChangeParams$.next(t);
|
|
@@ -247,7 +247,7 @@ const Y = "doc.mutation.rich-text-editing", M = {
|
|
|
247
247
|
type: P.MUTATION,
|
|
248
248
|
// eslint-disable-next-line max-lines-per-function
|
|
249
249
|
handler: (i, e) => {
|
|
250
|
-
var
|
|
250
|
+
var z, F;
|
|
251
251
|
const {
|
|
252
252
|
unitId: t,
|
|
253
253
|
segmentId: n = "",
|
|
@@ -256,27 +256,27 @@ const Y = "doc.mutation.rich-text-editing", M = {
|
|
|
256
256
|
prevTextRanges: o,
|
|
257
257
|
trigger: c,
|
|
258
258
|
noHistory: a,
|
|
259
|
-
isCompositionEnd:
|
|
259
|
+
isCompositionEnd: u,
|
|
260
260
|
noNeedSetTextRange: d,
|
|
261
261
|
debounce: h,
|
|
262
262
|
isEditing: g = !0,
|
|
263
263
|
isSync: _,
|
|
264
264
|
syncer: f
|
|
265
|
-
} = e,
|
|
265
|
+
} = e, v = i.get(I), p = i.get(Re), R = i.get(ne), S = v.getUniverDocInstance(t), j = (z = p.getRenderById(t)) == null ? void 0 : z.with(T).getViewModel();
|
|
266
266
|
if (S == null || j == null)
|
|
267
267
|
throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
|
|
268
|
-
const L = i.get(m),
|
|
269
|
-
if (x.isNoop(s) || s && s.length === 0 ||
|
|
268
|
+
const L = i.get(m), U = (F = L.getDocRanges()) != null ? F : [], se = !!S.getSnapshot().disabled;
|
|
269
|
+
if (x.isNoop(s) || s && s.length === 0 || se)
|
|
270
270
|
return {
|
|
271
271
|
unitId: t,
|
|
272
272
|
actions: [],
|
|
273
|
-
textRanges:
|
|
273
|
+
textRanges: U
|
|
274
274
|
};
|
|
275
275
|
const X = x.invertWithDoc(s, S.getSnapshot());
|
|
276
276
|
S.apply(s), j.reset(S), !d && r && c != null && !_ && queueMicrotask(() => {
|
|
277
277
|
L.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
|
|
278
278
|
});
|
|
279
|
-
const
|
|
279
|
+
const ie = {
|
|
280
280
|
commandId: Y,
|
|
281
281
|
unitId: t,
|
|
282
282
|
segmentId: n,
|
|
@@ -289,42 +289,45 @@ const Y = "doc.mutation.rich-text-editing", M = {
|
|
|
289
289
|
},
|
|
290
290
|
undoState: {
|
|
291
291
|
actions: X,
|
|
292
|
-
textRanges: o != null ? o :
|
|
292
|
+
textRanges: o != null ? o : U
|
|
293
293
|
},
|
|
294
|
-
isCompositionEnd:
|
|
294
|
+
isCompositionEnd: u,
|
|
295
295
|
isSync: _,
|
|
296
296
|
syncer: f
|
|
297
297
|
};
|
|
298
|
-
return
|
|
298
|
+
return R.emitStateChangeInfo(ie), {
|
|
299
299
|
unitId: t,
|
|
300
300
|
actions: X,
|
|
301
|
-
textRanges:
|
|
301
|
+
textRanges: U
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
|
-
},
|
|
304
|
+
}, Te = "@univerjs/docs", ye = "0.17.0", K = {
|
|
305
|
+
name: Te,
|
|
306
|
+
version: ye
|
|
307
|
+
}, we = {
|
|
305
308
|
id: "doc.mutation.rename-doc",
|
|
306
309
|
type: P.MUTATION,
|
|
307
310
|
handler: (i, e) => {
|
|
308
|
-
const n = i.get(I).getUnit(e.unitId,
|
|
311
|
+
const n = i.get(I).getUnit(e.unitId, w.UNIVER_DOC);
|
|
309
312
|
return n ? (n.setName(e.name), !0) : !1;
|
|
310
313
|
}
|
|
311
|
-
},
|
|
312
|
-
var
|
|
313
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
314
|
+
}, be = "docs.config", H = {};
|
|
315
|
+
var Ue = Object.getOwnPropertyDescriptor, $e = (i, e, t, n) => {
|
|
316
|
+
for (var s = n > 1 ? void 0 : n ? Ue(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
314
317
|
(o = i[r]) && (s = o(s) || s);
|
|
315
318
|
return s;
|
|
316
|
-
},
|
|
317
|
-
let
|
|
319
|
+
}, E = (i, e) => (t, n) => e(t, n, i);
|
|
320
|
+
let y = class extends Z {
|
|
318
321
|
constructor(i, e, t) {
|
|
319
322
|
super(), this._commandService = i, this._textSelectionManagerService = e, this._univerInstanceService = t, this._initSelectionChange();
|
|
320
323
|
}
|
|
321
324
|
_transformCustomRange(i, e) {
|
|
322
325
|
var o;
|
|
323
|
-
const { startOffset: t, endOffset: n, collapsed: s } = e, r = (o = i.getCustomRanges()) == null ? void 0 : o.filter((c) => !c.wholeEntity || t <= c.startIndex && n > c.endIndex ? !1 : s ? c.startIndex < t && c.endIndex >= n :
|
|
326
|
+
const { startOffset: t, endOffset: n, collapsed: s } = e, r = (o = i.getCustomRanges()) == null ? void 0 : o.filter((c) => !c.wholeEntity || t <= c.startIndex && n > c.endIndex ? !1 : s ? c.startIndex < t && c.endIndex >= n : D.range.isIntersects(t, n - 1, c.startIndex, c.endIndex));
|
|
324
327
|
if (r != null && r.length) {
|
|
325
328
|
let c = t, a = n;
|
|
326
|
-
return r.forEach((
|
|
327
|
-
c = Math.min(
|
|
329
|
+
return r.forEach((u) => {
|
|
330
|
+
c = Math.min(u.startIndex, c), a = Math.max(u.endIndex + 1, a);
|
|
328
331
|
}), {
|
|
329
332
|
...e,
|
|
330
333
|
startOffset: c,
|
|
@@ -346,28 +349,26 @@ let T = class extends Q {
|
|
|
346
349
|
}));
|
|
347
350
|
}
|
|
348
351
|
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
],
|
|
354
|
-
var
|
|
355
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
352
|
+
y = $e([
|
|
353
|
+
E(0, B),
|
|
354
|
+
E(1, b(m)),
|
|
355
|
+
E(2, I)
|
|
356
|
+
], y);
|
|
357
|
+
var Ee = Object.getOwnPropertyDescriptor, Ne = (i, e, t, n) => {
|
|
358
|
+
for (var s = n > 1 ? void 0 : n ? Ee(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
356
359
|
(o = i[r]) && (s = o(s) || s);
|
|
357
360
|
return s;
|
|
358
|
-
},
|
|
359
|
-
|
|
360
|
-
var N;
|
|
361
|
-
let q = (N = class extends ue {
|
|
361
|
+
}, q = (i, e) => (t, n) => e(t, n, i), O;
|
|
362
|
+
let J = (O = class extends de {
|
|
362
363
|
// static override type = UniverInstanceType.UNIVER_DOC;
|
|
363
|
-
constructor(i =
|
|
364
|
+
constructor(i = H, e, t) {
|
|
364
365
|
super(), this._config = i, this._injector = e, this._configService = t;
|
|
365
|
-
const { ...n } =
|
|
366
|
+
const { ...n } = ge(
|
|
366
367
|
{},
|
|
367
|
-
|
|
368
|
+
H,
|
|
368
369
|
this._config
|
|
369
370
|
);
|
|
370
|
-
this._configService.setConfig(
|
|
371
|
+
this._configService.setConfig(be, n);
|
|
371
372
|
}
|
|
372
373
|
onStarting() {
|
|
373
374
|
this._initializeDependencies(), this._initializeCommands();
|
|
@@ -375,7 +376,7 @@ let q = (N = class extends ue {
|
|
|
375
376
|
_initializeCommands() {
|
|
376
377
|
[
|
|
377
378
|
M,
|
|
378
|
-
|
|
379
|
+
we,
|
|
379
380
|
k
|
|
380
381
|
].forEach((i) => {
|
|
381
382
|
this._injector.get(B).registerCommand(i);
|
|
@@ -384,42 +385,42 @@ let q = (N = class extends ue {
|
|
|
384
385
|
_initializeDependencies() {
|
|
385
386
|
[
|
|
386
387
|
[m],
|
|
387
|
-
[
|
|
388
|
-
[
|
|
388
|
+
[ne],
|
|
389
|
+
[y]
|
|
389
390
|
].forEach((i) => this._injector.add(i));
|
|
390
391
|
}
|
|
391
392
|
onReady() {
|
|
392
|
-
this._injector.get(
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
],
|
|
399
|
-
const
|
|
400
|
-
CUSTOM_RANGE:
|
|
401
|
-
CUSTOM_DECORATION:
|
|
393
|
+
this._injector.get(y);
|
|
394
|
+
}
|
|
395
|
+
}, l(O, "pluginName", "DOCS_PLUGIN"), l(O, "packageName", K.name), l(O, "version", K.version), O);
|
|
396
|
+
J = Ne([
|
|
397
|
+
q(1, b(le)),
|
|
398
|
+
q(2, ue)
|
|
399
|
+
], J);
|
|
400
|
+
const Pe = ee("CUSTOM_RANGE"), Ve = ee("CUSTOM_DECORATION"), N = {
|
|
401
|
+
CUSTOM_RANGE: Pe,
|
|
402
|
+
CUSTOM_DECORATION: Ve
|
|
402
403
|
};
|
|
403
|
-
var
|
|
404
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
404
|
+
var Be = Object.getOwnPropertyDescriptor, ke = (i, e, t, n) => {
|
|
405
|
+
for (var s = n > 1 ? void 0 : n ? Be(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
405
406
|
(o = i[r]) && (s = o(s) || s);
|
|
406
407
|
return s;
|
|
407
|
-
},
|
|
408
|
-
let
|
|
408
|
+
}, Ae = (i, e) => (t, n) => e(t, n, i);
|
|
409
|
+
let Q = class extends Z {
|
|
409
410
|
constructor(e, t) {
|
|
410
411
|
super();
|
|
411
|
-
|
|
412
|
+
l(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
412
413
|
this._context = e, this._docSkeletonManagerService = t;
|
|
413
414
|
const n = this._docSkeletonManagerService.getViewModel(), s = n.getDataModel().getUnitId();
|
|
414
|
-
if (s ===
|
|
415
|
+
if (s === he || s === _e)
|
|
415
416
|
return;
|
|
416
|
-
this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(
|
|
417
|
+
this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept(N.CUSTOM_RANGE, {
|
|
417
418
|
priority: -1,
|
|
418
419
|
handler: (o, c, a) => a(o)
|
|
419
420
|
}));
|
|
420
|
-
let r = new
|
|
421
|
+
let r = new $();
|
|
421
422
|
n.segmentViewModels$.subscribe((o) => {
|
|
422
|
-
r.dispose(), r = new
|
|
423
|
+
r.dispose(), r = new $(), o.forEach((c) => {
|
|
423
424
|
r.add(this.interceptDocumentViewModel(c));
|
|
424
425
|
});
|
|
425
426
|
}), this.disposeWithMe(r);
|
|
@@ -434,18 +435,18 @@ let J = class extends Q {
|
|
|
434
435
|
var c, a;
|
|
435
436
|
return ((c = o.priority) != null ? c : 0) - ((a = r.priority) != null ? a : 0);
|
|
436
437
|
})
|
|
437
|
-
), this.disposeWithMe(
|
|
438
|
+
), this.disposeWithMe(fe(() => Se(this._interceptorsByName.get(n), t)));
|
|
438
439
|
}
|
|
439
440
|
fetchThroughInterceptors(e) {
|
|
440
441
|
const t = e, n = this._interceptorsByName.get(t);
|
|
441
|
-
return
|
|
442
|
+
return Ie(n || []);
|
|
442
443
|
}
|
|
443
444
|
interceptDocumentViewModel(e) {
|
|
444
|
-
const t = new
|
|
445
|
+
const t = new $();
|
|
445
446
|
return t.add(e.registerCustomRangeInterceptor({
|
|
446
447
|
getCustomRange: (n) => {
|
|
447
448
|
var s;
|
|
448
|
-
return this.fetchThroughInterceptors(
|
|
449
|
+
return this.fetchThroughInterceptors(N.CUSTOM_RANGE)(
|
|
449
450
|
e.getCustomRangeRaw(n),
|
|
450
451
|
{
|
|
451
452
|
index: n,
|
|
@@ -456,7 +457,7 @@ let J = class extends Q {
|
|
|
456
457
|
},
|
|
457
458
|
getCustomDecoration: (n) => {
|
|
458
459
|
var s;
|
|
459
|
-
return this.fetchThroughInterceptors(
|
|
460
|
+
return this.fetchThroughInterceptors(N.CUSTOM_DECORATION)(
|
|
460
461
|
e.getCustomDecorationRaw(n),
|
|
461
462
|
{
|
|
462
463
|
index: n,
|
|
@@ -468,9 +469,9 @@ let J = class extends Q {
|
|
|
468
469
|
})), t;
|
|
469
470
|
}
|
|
470
471
|
};
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
],
|
|
472
|
+
Q = ke([
|
|
473
|
+
Ae(1, b(T))
|
|
474
|
+
], Q);
|
|
474
475
|
function A(i, e = "") {
|
|
475
476
|
if (!e)
|
|
476
477
|
return ["body"];
|
|
@@ -483,7 +484,7 @@ function A(i, e = "") {
|
|
|
483
484
|
return ["footers", e, "body"];
|
|
484
485
|
throw new Error("Segment id not found in headers or footers");
|
|
485
486
|
}
|
|
486
|
-
function
|
|
487
|
+
function Fe(i, e, t) {
|
|
487
488
|
const { unitId: n, segmentId: s } = e, o = i.get(I).getUnit(n);
|
|
488
489
|
if (!o)
|
|
489
490
|
return !1;
|
|
@@ -494,24 +495,24 @@ function Xe(i, e, t) {
|
|
|
494
495
|
actions: [],
|
|
495
496
|
textRanges: void 0
|
|
496
497
|
}
|
|
497
|
-
}, a = x.getInstance(),
|
|
498
|
-
if (!
|
|
498
|
+
}, a = x.getInstance(), u = D.customRange.add({ ...e, body: t });
|
|
499
|
+
if (!u)
|
|
499
500
|
return !1;
|
|
500
501
|
const d = A(o, s);
|
|
501
|
-
return c.params.actions = a.editOp(
|
|
502
|
+
return c.params.actions = a.editOp(u.serialize(), d), c;
|
|
502
503
|
}
|
|
503
504
|
function Ge(i, e) {
|
|
504
505
|
var S;
|
|
505
|
-
const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selections: c } = e, a = i.get(m),
|
|
506
|
+
const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selections: c } = e, a = i.get(m), u = i.get(I), d = c != null ? c : a.getTextRanges({ unitId: o, subUnitId: o }), h = (S = d == null ? void 0 : d[0]) == null ? void 0 : S.segmentId;
|
|
506
507
|
if (!(d != null && d.length))
|
|
507
508
|
return !1;
|
|
508
|
-
const g =
|
|
509
|
+
const g = u.getUnit(o, w.UNIVER_DOC);
|
|
509
510
|
if (!g)
|
|
510
511
|
return !1;
|
|
511
512
|
const _ = g.getSelfOrHeaderFooterModel(h).getBody();
|
|
512
513
|
if (!_)
|
|
513
514
|
return !1;
|
|
514
|
-
const f =
|
|
515
|
+
const f = D.customRange.add({
|
|
515
516
|
ranges: d,
|
|
516
517
|
rangeId: t,
|
|
517
518
|
rangeType: n,
|
|
@@ -522,7 +523,7 @@ function Ge(i, e) {
|
|
|
522
523
|
});
|
|
523
524
|
if (!f)
|
|
524
525
|
return !1;
|
|
525
|
-
const
|
|
526
|
+
const v = x.getInstance(), p = {
|
|
526
527
|
id: M.id,
|
|
527
528
|
params: {
|
|
528
529
|
unitId: o,
|
|
@@ -531,10 +532,10 @@ function Ge(i, e) {
|
|
|
531
532
|
segmentId: h
|
|
532
533
|
},
|
|
533
534
|
textX: f
|
|
534
|
-
},
|
|
535
|
-
return p.params.actions =
|
|
535
|
+
}, R = A(g, h);
|
|
536
|
+
return p.params.actions = v.editOp(f.serialize(), R), p;
|
|
536
537
|
}
|
|
537
|
-
function
|
|
538
|
+
function We(i, e) {
|
|
538
539
|
const { unitId: t, segmentId: n, insert: s } = e, o = i.get(I).getUnit(t);
|
|
539
540
|
if (!o)
|
|
540
541
|
return !1;
|
|
@@ -546,35 +547,35 @@ function ze(i, e) {
|
|
|
546
547
|
textRanges: void 0,
|
|
547
548
|
segmentId: n
|
|
548
549
|
}
|
|
549
|
-
}, a = x.getInstance(),
|
|
550
|
+
}, a = x.getInstance(), u = D.customRange.delete({
|
|
550
551
|
documentDataModel: o,
|
|
551
552
|
rangeId: e.rangeId,
|
|
552
553
|
insert: s,
|
|
553
554
|
segmentId: n
|
|
554
555
|
});
|
|
555
|
-
if (!
|
|
556
|
+
if (!u)
|
|
556
557
|
return !1;
|
|
557
558
|
const d = A(o, n);
|
|
558
|
-
return c.params.actions = a.editOp(
|
|
559
|
+
return c.params.actions = a.editOp(u.serialize(), d), c.params.textRanges = u.selections, c;
|
|
559
560
|
}
|
|
560
|
-
function
|
|
561
|
-
var f,
|
|
561
|
+
function Ye(i, e) {
|
|
562
|
+
var f, v, p, R;
|
|
562
563
|
const { unitId: t, body: n, doc: s } = e;
|
|
563
564
|
let r = s;
|
|
564
565
|
if (r || (r = i.get(I).getUnit(t)), !r)
|
|
565
566
|
return !1;
|
|
566
|
-
const o = (f = e.selection) == null ? void 0 : f.segmentId, c = (
|
|
567
|
+
const o = (f = e.selection) == null ? void 0 : f.segmentId, c = (v = r.getSelfOrHeaderFooterModel(o)) == null ? void 0 : v.getBody();
|
|
567
568
|
if (!c) return !1;
|
|
568
|
-
const a = i.get(m),
|
|
569
|
-
if (!
|
|
569
|
+
const a = i.get(m), u = (p = e.selection) != null ? p : a.getActiveTextRange();
|
|
570
|
+
if (!u || !c)
|
|
570
571
|
return !1;
|
|
571
|
-
const d = (
|
|
572
|
-
startOffset:
|
|
573
|
-
endOffset:
|
|
572
|
+
const d = (R = e.textRanges) != null ? R : [{
|
|
573
|
+
startOffset: u.startOffset + n.dataStream.length,
|
|
574
|
+
endOffset: u.startOffset + n.dataStream.length,
|
|
574
575
|
collapsed: !0,
|
|
575
576
|
segmentId: o
|
|
576
|
-
}], h =
|
|
577
|
-
selection:
|
|
577
|
+
}], h = D.selection.replace({
|
|
578
|
+
selection: u,
|
|
578
579
|
body: n,
|
|
579
580
|
doc: r
|
|
580
581
|
});
|
|
@@ -594,16 +595,16 @@ function Fe(i, e) {
|
|
|
594
595
|
return g.params.actions = _.editOp(h.serialize()), g;
|
|
595
596
|
}
|
|
596
597
|
export {
|
|
597
|
-
|
|
598
|
-
|
|
598
|
+
N as DOC_INTERCEPTOR_POINT,
|
|
599
|
+
Q as DocInterceptorService,
|
|
599
600
|
m as DocSelectionManagerService,
|
|
600
|
-
|
|
601
|
-
|
|
601
|
+
T as DocSkeletonManagerService,
|
|
602
|
+
ne as DocStateEmitService,
|
|
602
603
|
M as RichTextEditingMutation,
|
|
603
604
|
k as SetTextSelectionsOperation,
|
|
604
|
-
|
|
605
|
+
J as UniverDocsPlugin,
|
|
605
606
|
Ge as addCustomRangeBySelectionFactory,
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
607
|
+
Fe as addCustomRangeFactory,
|
|
608
|
+
We as deleteCustomRangeFactory,
|
|
609
|
+
Ye as replaceSelectionFactory
|
|
609
610
|
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export { type IRichTextEditingMutationParams, RichTextEditingMutation } from './commands/mutations/core-editing.mutation';
|
|
17
17
|
export { type ISetTextSelectionsOperationParams, SetTextSelectionsOperation } from './commands/operations/text-selection.operation';
|
|
18
|
-
export type { IUniverDocsConfig } from './
|
|
18
|
+
export type { IUniverDocsConfig } from './config/config';
|
|
19
19
|
export { UniverDocsPlugin } from './plugin';
|
|
20
20
|
export { DocInterceptorService } from './services/doc-interceptor/doc-interceptor.service';
|
|
21
21
|
export { DOC_INTERCEPTOR_POINT } from './services/doc-interceptor/interceptor-const';
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { IUniverDocsConfig } from './
|
|
1
|
+
import { IUniverDocsConfig } from './config/config';
|
|
2
2
|
import { IConfigService, Injector, Plugin } from '@univerjs/core';
|
|
3
3
|
export declare class UniverDocsPlugin extends Plugin {
|
|
4
4
|
private readonly _config;
|
|
5
5
|
_injector: Injector;
|
|
6
6
|
private readonly _configService;
|
|
7
7
|
static pluginName: string;
|
|
8
|
+
static packageName: string;
|
|
9
|
+
static version: string;
|
|
8
10
|
constructor(_config: Partial<IUniverDocsConfig> | undefined, _injector: Injector, _configService: IConfigService);
|
|
9
11
|
onStarting(): void;
|
|
10
12
|
private _initializeCommands;
|
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,p){"use strict";var de=Object.defineProperty;var ge=(l,r,v)=>r in l?de(l,r,{enumerable:!0,configurable:!0,writable:!0,value:v}):l[r]=v;var g=(l,r,v)=>ge(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.getOwnPropertyDescriptor,G=(c,s,e,t)=>{for(var n=t>1?void 0:t?L(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},N=(c,s)=>(e,t)=>s(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 p.Subject);g(this,"textSelection$",this._textSelection$.asObservable());g(this,"_refreshSelection$",new p.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(p.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=e.getUnitId();this._setCurrentSelectionNotRefresh({unitId:t,subUnitId:t})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(e=this._currentSelection){return this._getTextRanges(e)}refreshSelection(e=this._currentSelection){e!=null&&this._refresh(e)}__TEST_ONLY_setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}getTextRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.textRanges}getRectRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.rectRanges}getDocRanges(e=this._currentSelection){var 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,i){if(t==null)return;const{unitId:o,subUnitId:a}=t;this._refreshSelection$.next({unitId:o,subUnitId:a,docRanges:e,isEditing:n,options:i})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;const n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:i,subUnitId:o,segmentId:a,style:u,textRanges:d,rectRanges:h,isEditing:S}=n,I=[...d,...h].filter(_=>_.startOffset!=null&&_.endOffset!=null).sort((_,f)=>_.startOffset>f.startOffset?1:_.startOffset<f.startOffset?-1:0);this._commandService.executeCommand(M.id,{unitId:i,subUnitId:o,segmentId:a,style:u,isEditing:S,ranges:I})}dispose(){this._textSelection$.complete(),this._refreshSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_getTextRanges(e){var i;if(e==null)return;const{unitId:t,subUnitId:n=""}=e;return(i=this._textSelectionInfo.get(t))==null?void 0:i.get(n)}_refresh(e){const t=this._getTextRanges(e);if(t==null)return;const{textRanges:n,rectRanges:i}=t,o=[...n,...i],{unitId:a,subUnitId:u}=e;this._refreshSelection$.next({unitId:a,subUnitId:u,docRanges:o,isEditing:!1})}_replaceByParam(e){const{unitId:t,subUnitId:n,...i}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...i})}_addByParam(e){const{unitId:t,subUnitId:n,...i}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const o=this._textSelectionInfo.get(t);o.has(n)?o.get(n).textRanges.push(...e.textRanges):o.set(n,{...i})}},l.DocSelectionManagerService=G([N(0,r.ICommandService),N(1,r.IUniverInstanceService)],l.DocSelectionManagerService);var z=Object.getOwnPropertyDescriptor,W=(c,s,e,t)=>{for(var n=t>1?void 0:t?z(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},$=(c,s)=>(e,t)=>s(e,t,c);l.DocSkeletonManagerService=class extends r.RxDisposable{constructor(e,t,n){super();g(this,"_skeleton");g(this,"_docViewModel");g(this,"_currentSkeleton$",new p.BehaviorSubject(null));g(this,"currentSkeleton$",this._currentSkeleton$.asObservable());g(this,"_currentSkeletonBefore$",new p.BehaviorSubject(null));g(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());g(this,"_currentViewModel$",new p.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(p.takeUntil(this.dispose$)).subscribe(i=>{i&&i.getUnitId()===this._context.unitId&&this._update(i)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const e=this._context.unit;this._update(e)}_update(e){const t=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&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=W([$(1,r.Inject(r.LocaleService)),$(2,r.IUniverInstanceService)],l.DocSkeletonManagerService);class y extends r.RxDisposable{constructor(){super();g(this,"_docStateChangeParams$",new p.BehaviorSubject(null));g(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const P="doc.mutation.rich-text-editing",O={id:P,type:r.CommandType.MUTATION,handler:(c,s)=>{var X,F;const{unitId:e,segmentId:t="",actions:n,textRanges:i,prevTextRanges:o,trigger:a,noHistory:u,isCompositionEnd:d,noNeedSetTextRange:h,debounce:S,isEditing:I=!0,isSync:_,syncer:f}=s,D=c.get(r.IUniverInstanceService),R=c.get(v.IRenderManagerService),C=c.get(y),m=D.getUniverDocInstance(e),V=(X=R.getRenderById(e))==null?void 0:X.with(l.DocSkeletonManagerService).getViewModel();if(m==null||V==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const j=c.get(l.DocSelectionManagerService),E=(F=j.getDocRanges())!=null?F:[],le=!!m.getSnapshot().disabled;if(r.JSONX.isNoop(n)||n&&n.length===0||le)return{unitId:e,actions:[],textRanges:E};const A=r.JSONX.invertWithDoc(n,m.getSnapshot());m.apply(n),V.reset(m),!h&&i&&a!=null&&!_&&queueMicrotask(()=>{j.replaceDocRanges(i,{unitId:e,subUnitId:e},I,s.options)});const ue={commandId:P,unitId:e,segmentId:t,trigger:a,noHistory:u,debounce:S,redoState:{actions:n,textRanges:i},undoState:{actions:A,textRanges:o!=null?o:E},isCompositionEnd:d,isSync:_,syncer:f};return C.emitStateChangeInfo(ue),{unitId:e,actions:A,textRanges:E}}},J={id:"doc.mutation.rename-doc",type:r.CommandType.MUTATION,handler:(c,s)=>{const t=c.get(r.IUniverInstanceService).getUnit(s.unitId,r.UniverInstanceType.UNIVER_DOC);return t?(t.setName(s.name),!0):!1}},Y="docs.config",B={};var K=Object.getOwnPropertyDescriptor,q=(c,s,e,t)=>{for(var n=t>1?void 0:t?K(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},U=(c,s)=>(e,t)=>s(e,t,c);let T=class extends r.Disposable{constructor(c,s,e){super(),this._commandService=c,this._textSelectionManagerService=s,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(c,s){var o;const{startOffset:e,endOffset:t,collapsed:n}=s,i=(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(i!=null&&i.length){let a=e,u=t;return i.forEach(d=>{a=Math.min(d.startIndex,a),u=Math.max(d.endIndex+1,u)}),{...s,startOffset:a,endOffset:u,collapsed:a===u}}return s}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(c=>{if(c.id===M.id){const s=c.params,{unitId:e,ranges:t,isEditing:n}=s,i=this._univerInstanceService.getUnit(e);if(!i)return;const o=t.map(a=>this._transformCustomRange(i,a));o.some((a,u)=>t[u]!==a)&&this._textSelectionManagerService.replaceTextRanges(o,n)}}))}};T=q([U(0,r.ICommandService),U(1,r.Inject(l.DocSelectionManagerService)),U(2,r.IUniverInstanceService)],T);var H=Object.getOwnPropertyDescriptor,Q=(c,s,e,t)=>{for(var n=t>1?void 0:t?H(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},k=(c,s)=>(e,t)=>s(e,t,c);const Z="DOCS_PLUGIN";l.UniverDocsPlugin=(w=class extends r.Plugin{constructor(s=B,e,t){super(),this._config=s,this._injector=e,this._configService=t;const{...n}=r.merge({},B,this._config);this._configService.setConfig(Y,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[O,J,M].forEach(s=>{this._injector.get(r.ICommandService).registerCommand(s)})}_initializeDependencies(){[[l.DocSelectionManagerService],[y],[T]].forEach(s=>this._injector.add(s))}onReady(){this._injector.get(T)}},g(w,"pluginName",Z),w),l.UniverDocsPlugin=Q([k(1,r.Inject(r.Injector)),k(2,r.IConfigService)],l.UniverDocsPlugin);const ee=r.createInterceptorKey("CUSTOM_RANGE"),te=r.createInterceptorKey("CUSTOM_DECORATION"),x={CUSTOM_RANGE:ee,CUSTOM_DECORATION:te};var ne=Object.getOwnPropertyDescriptor,ie=(c,s,e,t)=>{for(var n=t>1?void 0:t?ne(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},se=(c,s)=>(e,t)=>s(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(),i=n.getDataModel().getUnitId();if(i===r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===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 i=this._interceptorsByName.get(n);return i.push(t),this._interceptorsByName.set(n,i.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 i;return this.fetchThroughInterceptors(x.CUSTOM_RANGE)(e.getCustomRangeRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customRanges:(i=e.getDataModel().getCustomRanges())!=null?i:[]})},getCustomDecoration:n=>{var i;return this.fetchThroughInterceptors(x.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(i=e.getDataModel().getCustomDecorations())!=null?i:[]})}})),t}},l.DocInterceptorService=ie([se(1,r.Inject(l.DocSkeletonManagerService))],l.DocInterceptorService);function b(c,s=""){if(!s)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[s])!=null)return["headers",s,"body"];if((t==null?void 0:t[s])!=null)return["footers",s,"body"];throw new Error("Segment id not found in headers or footers")}function re(c,s,e){const{unitId:t,segmentId:n}=s,o=c.get(r.IUniverInstanceService).getUnit(t);if(!o)return!1;const a={id:O.id,params:{unitId:s.unitId,actions:[],textRanges:void 0}},u=r.JSONX.getInstance(),d=r.BuildTextUtils.customRange.add({...s,body:e});if(!d)return!1;const h=b(o,n);return a.params.actions=u.editOp(d.serialize(),h),a}function oe(c,s){var m;const{rangeId:e,rangeType:t,wholeEntity:n,properties:i,unitId:o,selections:a}=s,u=c.get(l.DocSelectionManagerService),d=c.get(r.IUniverInstanceService),h=a!=null?a:u.getTextRanges({unitId:o,subUnitId:o}),S=(m=h==null?void 0:h[0])==null?void 0:m.segmentId;if(!(h!=null&&h.length))return!1;const I=d.getUnit(o,r.UniverInstanceType.UNIVER_DOC);if(!I)return!1;const _=I.getSelfOrHeaderFooterModel(S).getBody();if(!_)return!1;const f=r.BuildTextUtils.customRange.add({ranges:h,rangeId:e,rangeType:t,segmentId:S,wholeEntity:n,properties:i,body:_});if(!f)return!1;const D=r.JSONX.getInstance(),R={id:O.id,params:{unitId:o,actions:[],textRanges:f.selections,segmentId:S},textX:f},C=b(I,S);return R.params.actions=D.editOp(f.serialize(),C),R}function ce(c,s){const{unitId:e,segmentId:t,insert:n}=s,o=c.get(r.IUniverInstanceService).getUnit(e);if(!o)return!1;const a={id:O.id,params:{unitId:s.unitId,actions:[],textRanges:void 0,segmentId:t}},u=r.JSONX.getInstance(),d=r.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:s.rangeId,insert:n,segmentId:t});if(!d)return!1;const h=b(o,t);return a.params.actions=u.editOp(d.serialize(),h),a.params.textRanges=d.selections,a}function ae(c,s){var f,D,R,C;const{unitId:e,body:t,doc:n}=s;let i=n;if(i||(i=c.get(r.IUniverInstanceService).getUnit(e)),!i)return!1;const o=(f=s.selection)==null?void 0:f.segmentId,a=(D=i.getSelfOrHeaderFooterModel(o))==null?void 0:D.getBody();if(!a)return!1;const u=c.get(l.DocSelectionManagerService),d=(R=s.selection)!=null?R:u.getActiveTextRange();if(!d||!a)return!1;const h=(C=s.textRanges)!=null?C:[{startOffset:d.startOffset+t.dataStream.length,endOffset:d.startOffset+t.dataStream.length,collapsed:!0,segmentId:o}],S=r.BuildTextUtils.selection.replace({selection:d,body:t,doc:i});if(!S)return!1;const I={id:O.id,params:{unitId:e,actions:[],textRanges:h,debounce:!0,segmentId:o},textX:S},_=r.JSONX.getInstance();return I.params.actions=_.editOp(S.serialize()),I}l.DOC_INTERCEPTOR_POINT=x,l.DocStateEmitService=y,l.RichTextEditingMutation=O,l.SetTextSelectionsOperation=M,l.addCustomRangeBySelectionFactory=oe,l.addCustomRangeFactory=re,l.deleteCustomRangeFactory=ce,l.replaceSelectionFactory=ae,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,p){"use strict";var de=Object.defineProperty;var ge=(l,r,v)=>r in l?de(l,r,{enumerable:!0,configurable:!0,writable:!0,value:v}):l[r]=v;var g=(l,r,v)=>ge(l,typeof r!="symbol"?r+"":r,v);var M;const T={id:"doc.operation.set-selections",type:r.CommandType.OPERATION,handler:()=>!0};var z=Object.getOwnPropertyDescriptor,G=(c,s,e,t)=>{for(var n=t>1?void 0:t?z(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},N=(c,s)=>(e,t)=>s(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 p.Subject);g(this,"textSelection$",this._textSelection$.asObservable());g(this,"_refreshSelection$",new p.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(p.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=e.getUnitId();this._setCurrentSelectionNotRefresh({unitId:t,subUnitId:t})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(e=this._currentSelection){return this._getTextRanges(e)}refreshSelection(e=this._currentSelection){e!=null&&this._refresh(e)}__TEST_ONLY_setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}getTextRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.textRanges}getRectRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.rectRanges}getDocRanges(e=this._currentSelection){var 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,i){if(t==null)return;const{unitId:o,subUnitId:a}=t;this._refreshSelection$.next({unitId:o,subUnitId:a,docRanges:e,isEditing:n,options:i})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;const n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:i,subUnitId:o,segmentId:a,style:u,textRanges:d,rectRanges:h,isEditing:_}=n,I=[...d,...h].filter(S=>S.startOffset!=null&&S.endOffset!=null).sort((S,f)=>S.startOffset>f.startOffset?1:S.startOffset<f.startOffset?-1:0);this._commandService.executeCommand(T.id,{unitId:i,subUnitId:o,segmentId:a,style:u,isEditing:_,ranges:I})}dispose(){this._textSelection$.complete(),this._refreshSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_getTextRanges(e){var i;if(e==null)return;const{unitId:t,subUnitId:n=""}=e;return(i=this._textSelectionInfo.get(t))==null?void 0:i.get(n)}_refresh(e){const t=this._getTextRanges(e);if(t==null)return;const{textRanges:n,rectRanges:i}=t,o=[...n,...i],{unitId:a,subUnitId:u}=e;this._refreshSelection$.next({unitId:a,subUnitId:u,docRanges:o,isEditing:!1})}_replaceByParam(e){const{unitId:t,subUnitId:n,...i}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...i})}_addByParam(e){const{unitId:t,subUnitId:n,...i}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const o=this._textSelectionInfo.get(t);o.has(n)?o.get(n).textRanges.push(...e.textRanges):o.set(n,{...i})}},l.DocSelectionManagerService=G([N(0,r.ICommandService),N(1,r.IUniverInstanceService)],l.DocSelectionManagerService);var W=Object.getOwnPropertyDescriptor,J=(c,s,e,t)=>{for(var n=t>1?void 0:t?W(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},$=(c,s)=>(e,t)=>s(e,t,c);l.DocSkeletonManagerService=class extends r.RxDisposable{constructor(e,t,n){super();g(this,"_skeleton");g(this,"_docViewModel");g(this,"_currentSkeleton$",new p.BehaviorSubject(null));g(this,"currentSkeleton$",this._currentSkeleton$.asObservable());g(this,"_currentSkeletonBefore$",new p.BehaviorSubject(null));g(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());g(this,"_currentViewModel$",new p.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(p.takeUntil(this.dispose$)).subscribe(i=>{i&&i.getUnitId()===this._context.unitId&&this._update(i)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const e=this._context.unit;this._update(e)}_update(e){const t=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&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([$(1,r.Inject(r.LocaleService)),$(2,r.IUniverInstanceService)],l.DocSkeletonManagerService);class U extends r.RxDisposable{constructor(){super();g(this,"_docStateChangeParams$",new p.BehaviorSubject(null));g(this,"docStateChangeParams$",this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}}const P="doc.mutation.rich-text-editing",O={id:P,type:r.CommandType.MUTATION,handler:(c,s)=>{var F,L;const{unitId:e,segmentId:t="",actions:n,textRanges:i,prevTextRanges:o,trigger:a,noHistory:u,isCompositionEnd:d,noNeedSetTextRange:h,debounce:_,isEditing:I=!0,isSync:S,syncer:f}=s,D=c.get(r.IUniverInstanceService),R=c.get(v.IRenderManagerService),C=c.get(U),m=D.getUniverDocInstance(e),j=(F=R.getRenderById(e))==null?void 0:F.with(l.DocSkeletonManagerService).getViewModel();if(m==null||j==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const A=c.get(l.DocSelectionManagerService),E=(L=A.getDocRanges())!=null?L:[],le=!!m.getSnapshot().disabled;if(r.JSONX.isNoop(n)||n&&n.length===0||le)return{unitId:e,actions:[],textRanges:E};const X=r.JSONX.invertWithDoc(n,m.getSnapshot());m.apply(n),j.reset(m),!h&&i&&a!=null&&!S&&queueMicrotask(()=>{A.replaceDocRanges(i,{unitId:e,subUnitId:e},I,s.options)});const ue={commandId:P,unitId:e,segmentId:t,trigger:a,noHistory:u,debounce:_,redoState:{actions:n,textRanges:i},undoState:{actions:X,textRanges:o!=null?o:E},isCompositionEnd:d,isSync:S,syncer:f};return C.emitStateChangeInfo(ue),{unitId:e,actions:X,textRanges:E}}},B={name:"@univerjs/docs",version:"0.17.0"},Y={id:"doc.mutation.rename-doc",type:r.CommandType.MUTATION,handler:(c,s)=>{const t=c.get(r.IUniverInstanceService).getUnit(s.unitId,r.UniverInstanceType.UNIVER_DOC);return t?(t.setName(s.name),!0):!1}},K="docs.config",k={};var q=Object.getOwnPropertyDescriptor,H=(c,s,e,t)=>{for(var n=t>1?void 0:t?q(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},b=(c,s)=>(e,t)=>s(e,t,c);let x=class extends r.Disposable{constructor(c,s,e){super(),this._commandService=c,this._textSelectionManagerService=s,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(c,s){var o;const{startOffset:e,endOffset:t,collapsed:n}=s,i=(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(i!=null&&i.length){let a=e,u=t;return i.forEach(d=>{a=Math.min(d.startIndex,a),u=Math.max(d.endIndex+1,u)}),{...s,startOffset:a,endOffset:u,collapsed:a===u}}return s}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(c=>{if(c.id===T.id){const s=c.params,{unitId:e,ranges:t,isEditing:n}=s,i=this._univerInstanceService.getUnit(e);if(!i)return;const o=t.map(a=>this._transformCustomRange(i,a));o.some((a,u)=>t[u]!==a)&&this._textSelectionManagerService.replaceTextRanges(o,n)}}))}};x=H([b(0,r.ICommandService),b(1,r.Inject(l.DocSelectionManagerService)),b(2,r.IUniverInstanceService)],x);var Q=Object.getOwnPropertyDescriptor,Z=(c,s,e,t)=>{for(var n=t>1?void 0:t?Q(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},V=(c,s)=>(e,t)=>s(e,t,c);l.UniverDocsPlugin=(M=class extends r.Plugin{constructor(s=k,e,t){super(),this._config=s,this._injector=e,this._configService=t;const{...n}=r.merge({},k,this._config);this._configService.setConfig(K,n)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[O,Y,T].forEach(s=>{this._injector.get(r.ICommandService).registerCommand(s)})}_initializeDependencies(){[[l.DocSelectionManagerService],[U],[x]].forEach(s=>this._injector.add(s))}onReady(){this._injector.get(x)}},g(M,"pluginName","DOCS_PLUGIN"),g(M,"packageName",B.name),g(M,"version",B.version),M),l.UniverDocsPlugin=Z([V(1,r.Inject(r.Injector)),V(2,r.IConfigService)],l.UniverDocsPlugin);const ee=r.createInterceptorKey("CUSTOM_RANGE"),te=r.createInterceptorKey("CUSTOM_DECORATION"),y={CUSTOM_RANGE:ee,CUSTOM_DECORATION:te};var ne=Object.getOwnPropertyDescriptor,ie=(c,s,e,t)=>{for(var n=t>1?void 0:t?ne(s,e):s,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},se=(c,s)=>(e,t)=>s(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(),i=n.getDataModel().getUnitId();if(i===r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===r.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(n)),this.disposeWithMe(this.intercept(y.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 i=this._interceptorsByName.get(n);return i.push(t),this._interceptorsByName.set(n,i.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 i;return this.fetchThroughInterceptors(y.CUSTOM_RANGE)(e.getCustomRangeRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customRanges:(i=e.getDataModel().getCustomRanges())!=null?i:[]})},getCustomDecoration:n=>{var i;return this.fetchThroughInterceptors(y.CUSTOM_DECORATION)(e.getCustomDecorationRaw(n),{index:n,unitId:e.getDataModel().getUnitId(),customDecorations:(i=e.getDataModel().getCustomDecorations())!=null?i:[]})}})),t}},l.DocInterceptorService=ie([se(1,r.Inject(l.DocSkeletonManagerService))],l.DocInterceptorService);function w(c,s=""){if(!s)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[s])!=null)return["headers",s,"body"];if((t==null?void 0:t[s])!=null)return["footers",s,"body"];throw new Error("Segment id not found in headers or footers")}function re(c,s,e){const{unitId:t,segmentId:n}=s,o=c.get(r.IUniverInstanceService).getUnit(t);if(!o)return!1;const a={id:O.id,params:{unitId:s.unitId,actions:[],textRanges:void 0}},u=r.JSONX.getInstance(),d=r.BuildTextUtils.customRange.add({...s,body:e});if(!d)return!1;const h=w(o,n);return a.params.actions=u.editOp(d.serialize(),h),a}function oe(c,s){var m;const{rangeId:e,rangeType:t,wholeEntity:n,properties:i,unitId:o,selections:a}=s,u=c.get(l.DocSelectionManagerService),d=c.get(r.IUniverInstanceService),h=a!=null?a:u.getTextRanges({unitId:o,subUnitId:o}),_=(m=h==null?void 0:h[0])==null?void 0:m.segmentId;if(!(h!=null&&h.length))return!1;const I=d.getUnit(o,r.UniverInstanceType.UNIVER_DOC);if(!I)return!1;const S=I.getSelfOrHeaderFooterModel(_).getBody();if(!S)return!1;const f=r.BuildTextUtils.customRange.add({ranges:h,rangeId:e,rangeType:t,segmentId:_,wholeEntity:n,properties:i,body:S});if(!f)return!1;const D=r.JSONX.getInstance(),R={id:O.id,params:{unitId:o,actions:[],textRanges:f.selections,segmentId:_},textX:f},C=w(I,_);return R.params.actions=D.editOp(f.serialize(),C),R}function ce(c,s){const{unitId:e,segmentId:t,insert:n}=s,o=c.get(r.IUniverInstanceService).getUnit(e);if(!o)return!1;const a={id:O.id,params:{unitId:s.unitId,actions:[],textRanges:void 0,segmentId:t}},u=r.JSONX.getInstance(),d=r.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:s.rangeId,insert:n,segmentId:t});if(!d)return!1;const h=w(o,t);return a.params.actions=u.editOp(d.serialize(),h),a.params.textRanges=d.selections,a}function ae(c,s){var f,D,R,C;const{unitId:e,body:t,doc:n}=s;let i=n;if(i||(i=c.get(r.IUniverInstanceService).getUnit(e)),!i)return!1;const o=(f=s.selection)==null?void 0:f.segmentId,a=(D=i.getSelfOrHeaderFooterModel(o))==null?void 0:D.getBody();if(!a)return!1;const u=c.get(l.DocSelectionManagerService),d=(R=s.selection)!=null?R:u.getActiveTextRange();if(!d||!a)return!1;const h=(C=s.textRanges)!=null?C:[{startOffset:d.startOffset+t.dataStream.length,endOffset:d.startOffset+t.dataStream.length,collapsed:!0,segmentId:o}],_=r.BuildTextUtils.selection.replace({selection:d,body:t,doc:i});if(!_)return!1;const I={id:O.id,params:{unitId:e,actions:[],textRanges:h,debounce:!0,segmentId:o},textX:_},S=r.JSONX.getInstance();return I.params.actions=S.editOp(_.serialize()),I}l.DOC_INTERCEPTOR_POINT=y,l.DocStateEmitService=U,l.RichTextEditingMutation=O,l.SetTextSelectionsOperation=T,l.addCustomRangeBySelectionFactory=oe,l.addCustomRangeFactory=re,l.deleteCustomRangeFactory=ce,l.replaceSelectionFactory=ae,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.
|
|
3
|
+
"version": "0.17.0",
|
|
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.
|
|
52
|
-
"@univerjs/engine-render": "0.
|
|
51
|
+
"@univerjs/core": "0.17.0",
|
|
52
|
+
"@univerjs/engine-render": "0.17.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"rxjs": "^7.8.2",
|
|
56
56
|
"typescript": "^5.9.3",
|
|
57
57
|
"vite": "^7.3.1",
|
|
58
58
|
"vitest": "^4.0.18",
|
|
59
|
-
"@univerjs-infra/shared": "0.
|
|
59
|
+
"@univerjs-infra/shared": "0.17.0"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"test": "vitest run",
|
|
File without changes
|