@univerjs/preset-docs-node-core 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/umd/index.js +4 -4
- package/package.json +11 -11
package/lib/umd/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// @univerjs/docs/index
|
|
2
|
-
(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"})}));
|
|
2
|
+
(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"})}));
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
// @univerjs/rpc-node/index
|
|
6
|
-
(function(e,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("node:child_process"),require("node:process"),require("@univerjs/core"),require("@univerjs/rpc"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","node:child_process","node:process","@univerjs/core","@univerjs/rpc","rxjs"],o):(e=typeof globalThis<"u"?globalThis:e||self,o(e.UniverRpcNode={},e.node_child_process,e.process,e.UniverCore,e.UniverRpc,e.rxjs))})(this,(function(e,o,l,a,s,
|
|
6
|
+
(function(e,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("node:child_process"),require("node:process"),require("@univerjs/core"),require("@univerjs/rpc"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","node:child_process","node:process","@univerjs/core","@univerjs/rpc","rxjs"],o):(e=typeof globalThis<"u"?globalThis:e||self,o(e.UniverRpcNode={},e.node_child_process,e.process,e.UniverCore,e.UniverRpc,e.rxjs))})(this,(function(e,o,l,a,s,_){"use strict";var U=Object.defineProperty;var k=(e,o,l)=>o in e?U(e,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[o]=l;var u=(e,o,l)=>k(e,typeof o!="symbol"?o+"":o,l);var h,v;const f={name:"@univerjs/rpc-node",version:"0.17.0"},p="rpc-node.main-thread.config",C={},N="rpc-node.worker-thread.config",R={};var S=Object.getOwnPropertyDescriptor,m=(t,r,n,i)=>{for(var d=i>1?void 0:i?S(r,n):r,c=t.length-1,g;c>=0;c--)(g=t[c])&&(d=g(d)||d);return d},P=(t,r)=>(n,i)=>r(n,i,t);e.UniverRPCNodeMainPlugin=(h=class extends a.Plugin{constructor(n=C,i,d){super();u(this,"_child",null);this._config=n,this._injector=i,this._configService=d;const{...c}=a.merge({},C,this._config);this._configService.setConfig(p,c)}onStarting(){const{workerSrc:n}=this._config;if(!n)throw new Error("[UniverRPCNodeMainPlugin] workerSrc is required for UniverRPCNodeMainPlugin");const[i,d]=I(this._injector,n);[[s.IRPCChannelService,{useFactory:()=>new s.ChannelService(i)}],[s.DataSyncPrimaryController],[s.IRemoteSyncService,{useClass:s.RemoteSyncPrimaryService}]].forEach(g=>this._injector.add(g)),this._injector.get(s.DataSyncPrimaryController),this._child=d}dispose(){if(super.dispose(),this._child){try{this._child.kill()}catch(n){console.error("Failed to kill child process:",n)}this._child=null}}},u(h,"pluginName","UNIVER_RPC_NODE_MAIN_PLUGIN"),u(h,"packageName",f.name),u(h,"version",f.version),h),e.UniverRPCNodeMainPlugin=m([P(1,a.Inject(a.Injector)),P(2,a.IConfigService)],e.UniverRPCNodeMainPlugin),e.UniverRPCNodeWorkerPlugin=(v=class extends a.Plugin{constructor(r=R,n,i){super(),this._config=r,this._injector=n,this._configService=i;const{...d}=a.merge({},R,this._config);this._configService.setConfig(N,d)}onStarting(){[[s.DataSyncReplicaController],[s.IRPCChannelService,{useFactory:()=>new s.ChannelService(j())}],[s.IRemoteInstanceService,{useClass:s.WebWorkerRemoteInstanceService}]].forEach(r=>this._injector.add(r)),this._injector.get(s.DataSyncReplicaController)}},u(v,"pluginName","UNIVER_RPC_NODE_WORKER_PLUGIN"),u(v,"packageName",f.name),u(v,"version",f.version),v),e.UniverRPCNodeWorkerPlugin=m([P(1,a.Inject(a.Injector)),P(2,a.IConfigService)],e.UniverRPCNodeWorkerPlugin);function I(t,r){const n=t.get(a.ILogService),i=o.fork(r);return i.on("spawn",()=>n.log("Child computing process spawned!")),i.on("error",c=>n.error(c)),[{send(c){i.send(c)},onMessage:new _.Observable(c=>{const g=y=>{c.next(y)};return i.on("message",g),()=>i.off("message",g)}).pipe(_.shareReplay(1))},i]}function j(){return{send(t){l.send(t)},onMessage:new _.Observable(t=>{const r=n=>{t.next(n)};return l.on("message",r),()=>l.off("message",r)}).pipe(_.shareReplay(1))}}Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
// @univerjs/docs-hyper-link/index
|
|
10
|
-
(function(a,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@univerjs/core")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core"],e):(a=typeof globalThis<"u"?globalThis:a||self,e(a.UniverDocsHyperLink={},a.UniverCore))})(this,(function(a,e){"use strict";var
|
|
10
|
+
(function(a,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@univerjs/core")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core"],e):(a=typeof globalThis<"u"?globalThis:a||self,e(a.UniverDocsHyperLink={},a.UniverCore))})(this,(function(a,e){"use strict";var T=Object.defineProperty;var E=(a,e,v)=>e in a?T(a,e,{enumerable:!0,configurable:!0,writable:!0,value:v}):a[e]=v;var l=(a,e,v)=>E(a,typeof e!="symbol"?e+"":e,v);var p;const _={name:"@univerjs/docs-hyper-link",version:"0.17.0"},m={id:"docs.mutation.add-hyper-link",type:e.CommandType.MUTATION,handler:()=>!0},U={id:"docs.mutation.update-hyper-link",type:e.CommandType.MUTATION,handler:()=>!0},C={id:"docs.mutation.delete-hyper-link",type:e.CommandType.MUTATION,handler:()=>!0},D="docs-hyper-link.config",f={};var P=Object.getOwnPropertyDescriptor,M=(s,n,t,o)=>{for(var i=o>1?void 0:o?P(n,t):n,r=s.length-1,c;r>=0;r--)(c=s[r])&&(i=c(i)||i);return i},y=(s,n)=>(t,o)=>n(t,o,s);const I="DOC_HYPER_LINK_PLUGIN";let g=class extends e.Disposable{constructor(s,n){super(),this._resourceManagerService=s,this._univerInstanceService=n,this._init()}_init(){this._resourceManagerService.registerPluginResource({pluginName:I,businesses:[e.UniverInstanceType.UNIVER_DOC],onLoad:(s,n)=>{const t=this._univerInstanceService.getUnit(s,e.UniverInstanceType.UNIVER_DOC);if(!t)return;const o=new Map,i=r=>{var c,d;return(d=(c=r.getBody())==null?void 0:c.customRanges)==null||d.forEach(u=>{u.rangeType===e.CustomRangeType.HYPERLINK&&o.set(u.rangeId,u)}),o};t.headerModelMap.forEach(r=>{i(r)}),t.footerModelMap.forEach(r=>{i(r)}),i(t),n.links.forEach(r=>{const c=o.get(r.id);c&&(c.properties={...c.properties,url:r.payload})})},onUnLoad:s=>{},toJson:s=>{const n=this._univerInstanceService.getUnit(s,e.UniverInstanceType.UNIVER_DOC),t=[];if(n){const o=i=>{var r,c;(c=(r=i.getBody())==null?void 0:r.customRanges)==null||c.forEach(d=>{var u;d.rangeType===e.CustomRangeType.HYPERLINK&&t.push({id:d.rangeId,payload:((u=d.properties)==null?void 0:u.url)||""})})};n.headerModelMap.forEach(i=>{o(i)}),n.footerModelMap.forEach(i=>{o(i)}),o(n)}return JSON.stringify({links:t})},parseJson(s){return JSON.parse(s)}})}};g=M([y(0,e.Inject(e.IResourceManagerService)),y(1,e.IUniverInstanceService)],g);var N=Object.getOwnPropertyDescriptor,O=(s,n,t,o)=>{for(var i=o>1?void 0:o?N(n,t):n,r=s.length-1,c;r>=0;r--)(c=s[r])&&(i=c(i)||i);return i},h=(s,n)=>(t,o)=>n(t,o,s);a.UniverDocsHyperLinkPlugin=(p=class extends e.Plugin{constructor(n=f,t,o,i){super(),this._config=n,this._injector=t,this._configService=o,this._commandService=i;const{...r}=e.merge({},f,this._config);this._configService.setConfig(D,r)}onStarting(){[[g]].forEach(t=>this._injector.add(t)),[m,C,U].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))}),this._injector.get(g)}},l(p,"pluginName",I),l(p,"packageName",_.name),l(p,"version",_.version),l(p,"type",e.UniverInstanceType.UNIVER_DOC),p),a.UniverDocsHyperLinkPlugin=O([h(1,e.Inject(e.Injector)),h(2,e.IConfigService),h(3,e.ICommandService)],a.UniverDocsHyperLinkPlugin),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
// @univerjs/thread-comment/index
|
|
14
|
-
(function(d,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],s):(d=typeof globalThis<"u"?globalThis:d||self,s(d.UniverThreadComment={},d.UniverCore,d.rxjs))})(this,(function(d,s,M){"use strict";var B=Object.defineProperty;var q=(d,s,M)=>s in d?B(d,s,{enumerable:!0,configurable:!0,writable:!0,value:M}):d[s]=M;var u=(d,s,M)=>q(d,typeof s!="symbol"?s+"":s,M);var T;class I extends s.Disposable{constructor(){super();u(this,"_dataSource",null);u(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const a=e[o];n[o]=a.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const C=s.createIdentifier("univer.thread-comment.data-source-service");var H=Object.getOwnPropertyDescriptor,W=(c,m,e,t)=>{for(var n=t>1?void 0:t?H(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},N=(c,m)=>(e,t)=>m(e,t,c);d.ThreadCommentModel=class extends s.Disposable{constructor(e,t){super();u(this,"_commentsMap",new Map);u(this,"_threadMap",new Map);u(this,"_commentUpdate$",new M.Subject);u(this,"commentUpdate$",this._commentUpdate$.asObservable());u(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===s.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:a,subUnitId:r,threadIds:i})=>{let h=o.get(a);h||(h=new Map,o.set(a,h));let l=h.get(r);l||(l=new Set,h.set(r,l));for(const p of i)l.add(p)}),this._tasks=[],o.forEach((a,r)=>{a.forEach((i,h)=>{this.syncThreadComments(r,h,Array.from(i))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n.id);if(a){const{children:r,...i}=n,h={...i,ref:a.ref};o.set(n.id,h),r==null||r.forEach(l=>{o.set(l.id,{...l,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:h}),!!n.resolved!=!!a.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<s.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),a=this._ensureCommentMap(e,t),r=await this._dataSourceService.listThreadComments(e,t,n);if(!r)return;const i=new Set(n);r.forEach(h=>{this._replaceComment(e,t,h),i.delete(h.threadId)}),i.forEach(h=>{o.delete(h),a.forEach((l,p)=>{l.threadId===h&&a.delete(p)})})}addComment(e,t,n,o){const a=this._ensureCommentMap(e,t),{parentId:r,children:i=[],...h}=n,l={...h,parentId:r===n.id?void 0:r};l.threadId||(l.threadId=l.parentId||l.id);const p=f=>{a.set(f.id,f),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:f,isRoot:!f.parentId})};p(l);const L=this._ensureThreadMap(e,t);if(!l.parentId){L.set(l.threadId,l);for(const f of i)p(f)}return o&&this.syncThreadComments(e,t,[l.threadId]),!0}updateComment(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n.commentId);return r&&(r.updated=!0,r.text=n.text,r.attachments=n.attachments,r.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n.commentId);return r?(r.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:r.threadId}),!0):!1}resolveComment(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n);return r?(r.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),a=Array.from(o.values()).filter(l=>l.threadId===n);let r;const i=[],h=new Set;for(const l of a)l.parentId?i.push(l):r=l,h.add(l.personId);if(r)return{root:r,children:i,relativeUsers:h,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n);a&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!a.parentId,comment:a}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(r=>{r.threadId===n&&this._deleteComment(e,t,r.id)})}deleteComment(e,t,n){const a=this._ensureCommentMap(e,t).get(n);return a&&(a.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,a.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(a=>{this.deleteComment(e,o,a.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,a)=>{o.forEach((r,i)=>{const h=this.getThread(e,a,i);h&&n.push(h)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}},d.ThreadCommentModel=W([N(0,s.Inject(C)),N(1,s.Inject(s.LifecycleService))],d.ThreadCommentModel);const v={id:"thread-comment.mutation.add-comment",type:s.CommandType.MUTATION,handler(c,m,e){if(!m)return!1;const t=c.get(d.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:r}=m,i=r||(e==null?void 0:e.fromChangeset)&&!a.parentId;return t.addComment(n,o,a,i)}},g={id:"thread-comment.mutation.update-comment",type:s.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateComment(t,n,o,a)}},D={id:"thread-comment.mutation.update-comment-ref",type:s.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateCommentRef(t,n,o,a)}},S={id:"thread-comment.mutation.resolve-comment",type:s.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=m;return e.resolveComment(t,n,a,o)}},_={id:"thread-comment.mutation.delete-comment",type:s.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},O={id:"thread-comment.command.add-comment",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(s.ICommandService),t=c.get(C),{comment:n}=m,o=await t.addComment(n),a=t.syncUpdateMutationToColla,r=!n.parentId,i={id:v.id,params:{...m,comment:o}};return r?await e.executeCommand(i.id,i.params):e.executeCommand(i.id,i.params,{onlyLocal:!a})}},R={id:"thread-comment.command.update-comment",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=c.get(s.ICommandService),a=c.get(d.ThreadCommentModel),r=c.get(C),i=r.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...p}=h;if(!await r.updateComment({...p,...n}))return!1;const f={id:g.id,params:m};return o.executeCommand(f.id,f.params,{onlyLocal:!i}),!0}},w={id:"thread-comment.command.resolve-comment",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,a=c.get(C),i=c.get(d.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:c.get(s.ICommandService).executeCommand(S.id,m,{onlyLocal:!h})}},A={id:"thread-comment.command.delete-comment",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),t=c.get(C),n=c.get(s.ICommandService),{unitId:o,subUnitId:a,commentId:r}=m,i=t.syncUpdateMutationToColla,h=e.getComment(o,a,r);if(!h||!await t.deleteComment(o,a,h.threadId,r))return!1;const l={id:_.id,params:m};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},P={id:"thread-comment.command.delete-comment-tree",type:s.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(d.ThreadCommentModel),t=c.get(s.ICommandService),n=c.get(C),{unitId:o,subUnitId:a,commentId:r}=m,i=e.getCommentWithChildren(o,a,r);return!i||!await n.deleteComment(o,a,i.root.threadId,r)?!1:await t.executeCommand(_.id,{unitId:o,subUnitId:a,commentId:i.root.id})}};function G(c){return s.dayjs(c).format("YYYY/MM/DD HH:mm")}const y="UNIVER_THREAD_COMMENT_PLUGIN";var J=Object.getOwnPropertyDescriptor,V=(c,m,e,t)=>{for(var n=t>1?void 0:t?J(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},U=(c,m)=>(e,t)=>m(e,t,c);const j=`SHEET_${y}`;d.ThreadCommentResourceController=class extends s.Disposable{constructor(m,e,t){super(),this._resourceManagerService=m,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const m=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(a=>{var i;const r=(i=o[a.subUnitId])!=null?i:[];r.push({...a.root,children:a.children}),o[a.subUnitId]=r}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:j,businesses:[s.UniverInstanceType.UNIVER_SHEET,s.UniverInstanceType.UNIVER_DOC],toJson:t=>m(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const a=n[o];a.forEach(r=>{this._threadCommentModel.addComment(t,o,r)}),this._threadCommentModel.syncThreadComments(t,o,a.map(r=>r.threadId))})}}))}},d.ThreadCommentResourceController=V([U(0,s.IResourceManagerService),U(1,s.Inject(d.ThreadCommentModel)),U(2,C)],d.ThreadCommentResourceController);const b="thread-comment.config",$={};var Y=Object.getOwnPropertyDescriptor,k=(c,m,e,t)=>{for(var n=t>1?void 0:t?Y(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},E=(c,m)=>(e,t)=>m(e,t,c);d.UniverThreadCommentPlugin=(T=class extends s.Plugin{constructor(m=$,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=s.merge({},$,this._config);this._configService.setConfig(b,o)}onStarting(){var m;s.mergeOverrideWithDependencies([[C,{useClass:I}],[d.ThreadCommentModel],[d.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[O,R,A,w,P,v,g,D,_,S].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(d.ThreadCommentResourceController)}},u(T,"pluginName",y),u(T,"type",s.UniverInstanceType.UNIVER_UNKNOWN),T),d.UniverThreadCommentPlugin=k([E(1,s.Inject(s.Injector)),E(2,s.ICommandService),E(3,s.IConfigService)],d.UniverThreadCommentPlugin),d.AddCommentCommand=O,d.AddCommentMutation=v,d.DeleteCommentCommand=A,d.DeleteCommentMutation=_,d.DeleteCommentTreeCommand=P,d.IThreadCommentDataSourceService=C,d.ResolveCommentCommand=w,d.ResolveCommentMutation=S,d.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=j,d.TC_PLUGIN_NAME=y,d.ThreadCommentDataSourceService=I,d.UpdateCommentCommand=R,d.UpdateCommentMutation=g,d.UpdateCommentRefMutation=D,d.getDT=G,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|
|
14
|
+
(function(s,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],d):(s=typeof globalThis<"u"?globalThis:s||self,d(s.UniverThreadComment={},s.UniverCore,s.rxjs))})(this,(function(s,d,M){"use strict";var q=Object.defineProperty;var K=(s,d,M)=>d in s?q(s,d,{enumerable:!0,configurable:!0,writable:!0,value:M}):s[d]=M;var u=(s,d,M)=>K(s,typeof d!="symbol"?d+"":d,M);var _;class I extends d.Disposable{constructor(){super();u(this,"_dataSource",null);u(this,"syncUpdateMutationToColla",!0)}set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)!=null?t:e.id}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,o){return this._dataSource?this._dataSource.deleteComment(e,t,n,o):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){const n={};return Object.keys(e).forEach(o=>{const a=e[o];n[o]=a.map(this.dataSource.saveCommentToSnapshot)}),n}return e}}const C=d.createIdentifier("univer.thread-comment.data-source-service");var W=Object.getOwnPropertyDescriptor,G=(c,m,e,t)=>{for(var n=t>1?void 0:t?W(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},N=(c,m)=>(e,t)=>m(e,t,c);s.ThreadCommentModel=class extends d.Disposable{constructor(e,t){super();u(this,"_commentsMap",new Map);u(this,"_threadMap",new Map);u(this,"_commentUpdate$",new M.Subject);u(this,"commentUpdate$",this._commentUpdate$.asObservable());u(this,"_tasks",[]);this._dataSourceService=e,this._lifecycleService=t,this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(n=>{const o=new Map;n===d.LifecycleStages.Rendered&&(this._tasks.forEach(({unitId:a,subUnitId:r,threadIds:i})=>{let h=o.get(a);h||(h=new Map,o.set(a,h));let l=h.get(r);l||(l=new Set,h.set(r,l));for(const p of i)l.add(p)}),this._tasks=[],o.forEach((a,r)=>{a.forEach((i,h)=>{this.syncThreadComments(r,h,Array.from(i))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_replaceComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n.id);if(a){const{children:r,...i}=n,h={...i,ref:a.ref};o.set(n.id,h),r==null||r.forEach(l=>{o.set(l.id,{...l,ref:""})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"syncUpdate",payload:h}),!!n.resolved!=!!a.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<d.LifecycleStages.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}const o=this._ensureThreadMap(e,t),a=this._ensureCommentMap(e,t),r=await this._dataSourceService.listThreadComments(e,t,n);if(!r)return;const i=new Set(n);r.forEach(h=>{this._replaceComment(e,t,h),i.delete(h.threadId)}),i.forEach(h=>{o.delete(h),a.forEach((l,p)=>{l.threadId===h&&a.delete(p)})})}addComment(e,t,n,o){const a=this._ensureCommentMap(e,t),{parentId:r,children:i=[],...h}=n,l={...h,parentId:r===n.id?void 0:r};l.threadId||(l.threadId=l.parentId||l.id);const p=f=>{a.set(f.id,f),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"add",payload:f,isRoot:!f.parentId})};p(l);const H=this._ensureThreadMap(e,t);if(!l.parentId){H.set(l.threadId,l);for(const f of i)p(f)}return o&&this.syncThreadComments(e,t,[l.threadId]),!0}updateComment(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n.commentId);return r&&(r.updated=!0,r.text=n.text,r.attachments=n.attachments,r.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"update",payload:n,silent:o})),!0}updateCommentRef(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n.commentId);return r?(r.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"updateRef",payload:n,silent:o,threadId:r.threadId}),!0):!1}resolveComment(e,t,n,o){const r=this._ensureCommentMap(e,t).get(n);return r?(r.resolved=o,this._commentUpdate$.next({unitId:e,subUnitId:t,type:"resolve",payload:{commentId:n,resolved:o}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){const o=this._ensureCommentMap(e,t),a=Array.from(o.values()).filter(l=>l.threadId===n);let r;const i=[],h=new Set;for(const l of a)l.parentId?i.push(l):r=l,h.add(l.personId);if(r)return{root:r,children:i,relativeUsers:h,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){const o=this.getComment(e,t,n);if(o)return this.getThread(e,t,o.threadId)}_deleteComment(e,t,n){const o=this._ensureCommentMap(e,t),a=o.get(n);a&&(o.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:"delete",payload:{commentId:n,isRoot:!a.parentId,comment:a}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(r=>{r.threadId===n&&this._deleteComment(e,t,r.id)})}deleteComment(e,t,n){const a=this._ensureCommentMap(e,t).get(n);return a&&(a.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,a.threadId)),!0}deleteUnit(e){const t=this._commentsMap.get(e);t&&t.forEach((n,o)=>{n.forEach(a=>{this.deleteComment(e,o,a.id)})})}getUnit(e){const t=this._threadMap.get(e);if(!t)return[];const n=[];return t.forEach((o,a)=>{o.forEach((r,i)=>{const h=this.getThread(e,a,i);h&&n.push(h)})}),n}getAll(){const e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}},s.ThreadCommentModel=G([N(0,d.Inject(C)),N(1,d.Inject(d.LifecycleService))],s.ThreadCommentModel);const v={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(c,m,e){if(!m)return!1;const t=c.get(s.ThreadCommentModel),{unitId:n,subUnitId:o,comment:a,sync:r}=m,i=r||(e==null?void 0:e.fromChangeset)&&!a.parentId;return t.addComment(n,o,a,i)}},g={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateComment(t,n,o,a)}},D={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,payload:o,silent:a}=m;return e.updateCommentRef(t,n,o,a)}},S={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,resolved:o,commentId:a}=m;return e.resolveComment(t,n,a,o)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),{unitId:t,subUnitId:n,commentId:o}=m;return e.deleteComment(t,n,o)}},O={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(d.ICommandService),t=c.get(C),{comment:n}=m,o=await t.addComment(n),a=t.syncUpdateMutationToColla,r=!n.parentId,i={id:v.id,params:{...m,comment:o}};return r?await e.executeCommand(i.id,i.params):e.executeCommand(i.id,i.params,{onlyLocal:!a})}},R={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const{unitId:e,subUnitId:t,payload:n}=m,o=c.get(d.ICommandService),a=c.get(s.ThreadCommentModel),r=c.get(C),i=r.syncUpdateMutationToColla,h=a.getComment(e,t,n.commentId);if(!h)return!1;const{children:l,...p}=h;if(!await r.updateComment({...p,...n}))return!1;const f={id:g.id,params:m};return o.executeCommand(f.id,f.params,{onlyLocal:!i}),!0}},w={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const{unitId:e,subUnitId:t,resolved:n,commentId:o}=m,a=c.get(C),i=c.get(s.ThreadCommentModel).getComment(e,t,o),h=a.syncUpdateMutationToColla;return!i||!await a.resolveComment({...i,resolved:n})?!1:c.get(d.ICommandService).executeCommand(S.id,m,{onlyLocal:!h})}},A={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),t=c.get(C),n=c.get(d.ICommandService),{unitId:o,subUnitId:a,commentId:r}=m,i=t.syncUpdateMutationToColla,h=e.getComment(o,a,r);if(!h||!await t.deleteComment(o,a,h.threadId,r))return!1;const l={id:T.id,params:m};return n.executeCommand(l.id,l.params,{onlyLocal:!i})}},P={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(c,m){if(!m)return!1;const e=c.get(s.ThreadCommentModel),t=c.get(d.ICommandService),n=c.get(C),{unitId:o,subUnitId:a,commentId:r}=m,i=e.getCommentWithChildren(o,a,r);return!i||!await n.deleteComment(o,a,i.root.threadId,r)?!1:await t.executeCommand(T.id,{unitId:o,subUnitId:a,commentId:i.root.id})}};function k(c){return d.dayjs(c).format("YYYY/MM/DD HH:mm")}const y="UNIVER_THREAD_COMMENT_PLUGIN";var J=Object.getOwnPropertyDescriptor,V=(c,m,e,t)=>{for(var n=t>1?void 0:t?J(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},U=(c,m)=>(e,t)=>m(e,t,c);const j=`SHEET_${y}`;s.ThreadCommentResourceController=class extends d.Disposable{constructor(m,e,t){super(),this._resourceManagerService=m,this._threadCommentModel=e,this._threadCommentDataSourceService=t,this._initSnapshot()}_initSnapshot(){const m=t=>{const n=this._threadCommentModel.getUnit(t),o={};return n?(n.forEach(a=>{var i;const r=(i=o[a.subUnitId])!=null?i:[];r.push({...a.root,children:a.children}),o[a.subUnitId]=r}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o,t))):""},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:j,businesses:[d.UniverInstanceType.UNIVER_SHEET,d.UniverInstanceType.UNIVER_DOC],toJson:t=>m(t),parseJson:t=>e(t),onUnLoad:t=>{this._threadCommentModel.deleteUnit(t)},onLoad:async(t,n)=>{Object.keys(n).forEach(o=>{const a=n[o];a.forEach(r=>{this._threadCommentModel.addComment(t,o,r)}),this._threadCommentModel.syncThreadComments(t,o,a.map(r=>r.threadId))})}}))}},s.ThreadCommentResourceController=V([U(0,d.IResourceManagerService),U(1,d.Inject(s.ThreadCommentModel)),U(2,C)],s.ThreadCommentResourceController);const $={name:"@univerjs/thread-comment",version:"0.17.0"},b="thread-comment.config",L={};var Y=Object.getOwnPropertyDescriptor,B=(c,m,e,t)=>{for(var n=t>1?void 0:t?Y(m,e):m,o=c.length-1,a;o>=0;o--)(a=c[o])&&(n=a(n)||n);return n},E=(c,m)=>(e,t)=>m(e,t,c);s.UniverThreadCommentPlugin=(_=class extends d.Plugin{constructor(m=L,e,t,n){super(),this._config=m,this._injector=e,this._commandService=t,this._configService=n;const{...o}=d.merge({},L,this._config);this._configService.setConfig(b,o)}onStarting(){var m;d.mergeOverrideWithDependencies([[C,{useClass:I}],[s.ThreadCommentModel],[s.ThreadCommentResourceController]],(m=this._config)==null?void 0:m.overrides).forEach(e=>{this._injector.add(e)}),[O,R,A,w,P,v,g,D,T,S].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(s.ThreadCommentResourceController)}},u(_,"pluginName",y),u(_,"packageName",$.name),u(_,"version",$.version),u(_,"type",d.UniverInstanceType.UNIVER_UNKNOWN),_),s.UniverThreadCommentPlugin=B([E(1,d.Inject(d.Injector)),E(2,d.ICommandService),E(3,d.IConfigService)],s.UniverThreadCommentPlugin),s.AddCommentCommand=O,s.AddCommentMutation=v,s.DeleteCommentCommand=A,s.DeleteCommentMutation=T,s.DeleteCommentTreeCommand=P,s.IThreadCommentDataSourceService=C,s.ResolveCommentCommand=w,s.ResolveCommentMutation=S,s.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=j,s.TC_PLUGIN_NAME=y,s.ThreadCommentDataSourceService=I,s.UpdateCommentCommand=R,s.UpdateCommentMutation=g,s.UpdateCommentRefMutation=D,s.getDT=k,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
// index
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/preset-docs-node-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -56,20 +56,20 @@
|
|
|
56
56
|
"rxjs": ">=7.0.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@univerjs/docs": "0.
|
|
60
|
-
"@univerjs/docs-drawing": "0.
|
|
61
|
-
"@univerjs/docs-hyper-link": "0.
|
|
62
|
-
"@univerjs/drawing": "0.
|
|
63
|
-
"@univerjs/engine-formula": "0.
|
|
64
|
-
"@univerjs/engine-render": "0.
|
|
65
|
-
"@univerjs/rpc-node": "0.
|
|
66
|
-
"@univerjs/thread-comment": "0.
|
|
59
|
+
"@univerjs/docs": "0.17.0",
|
|
60
|
+
"@univerjs/docs-drawing": "0.17.0",
|
|
61
|
+
"@univerjs/docs-hyper-link": "0.17.0",
|
|
62
|
+
"@univerjs/drawing": "0.17.0",
|
|
63
|
+
"@univerjs/engine-formula": "0.17.0",
|
|
64
|
+
"@univerjs/engine-render": "0.17.0",
|
|
65
|
+
"@univerjs/rpc-node": "0.17.0",
|
|
66
|
+
"@univerjs/thread-comment": "0.17.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@univerjs/core": "0.
|
|
69
|
+
"@univerjs/core": "0.17.0",
|
|
70
70
|
"rxjs": "7.8.2",
|
|
71
71
|
"typescript": "^5.9.3",
|
|
72
|
-
"@univerjs-infra/shared": "0.
|
|
72
|
+
"@univerjs-infra/shared": "0.17.0"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"prebuild:preset": "tsx prepare.ts",
|